I want to generate random numbers following a power law distribution, for what I wrote the next example:
[code]void genrand(Int_t nevnts = 100000, Double_t nbins = 10000., Double_t min = 1., Double_t max = 10000.)
TCanvas *c1 = new TCanvas(“c1”,“c1”,900,300);
TF1 *f1 = new TF1(“f1”, “1./x”, min, max);
// FillRandom() method
TH1D *h1 = new TH1D(“h1”,“Random Distribution from FillRandom()”,nbins,min,max);
// GetRandom() method
TH1D *h2 = new TH1D(“h2”,“Random Distribution from GetRandom()”,nbins,min,max);
for (int i=0; i<nevnts; i++)
rrd = f1->GetRandom();
cout << " FIN " << endl;
In my results (see attachment) I can see that the function is well defined, and that the first method used (with FillRandom() ) reproduced the function well. But when using GetRandom() function, I get a depth in the function, which position is related with the difference max-min.
I saw some post about the problem appearing when the point 0 is included, but I am excluding it in my example. I even tried to set the range directly f1->SetRange(1.,10000.), but it gave me the same result.
It seems for me that the function has problems to generate random numbers over more than 2 orders of magnitude (with min=1 and max=100 no depth appears).
Has anybody idea what could be the problem?
Thanks in advance,