Dear all,
I’m trying to draw random numbers from an inverse power law distribution and I see some strange behaviour which I’m unable to explain.
In the first instance I use a TF1 to define a power law function of the form x^-1, then use the GetRandom() function to generate random numbers from this distribution (over a small finite range) which I use to fill a histogram. Of course, in log-log space I would expect a linear output distribution with a slope of -1. What I see is a uniform distribution instead (very basic example below).
{
const int nSamples = 10000000;
TF1 fPowerLaw("fPowerLaw","x^-1",1,100);
TH1F histo("histo","Sampling from x^-1",100,1,2);
for (int i=0; i<nSamples; i++) histo.Fill( log10( fPowerLaw.GetRandom() ) );
TCanvas testCanvas;
testCanvas.SetLogy();
histo.Draw();
}
If I repeat the exercise with a power law of the form x^-2 I obtain a histogram with a slope of -1 in log-log space!
It seems that when randomly sampling an inverse power law distribution of the form “x^-k” the resulting distribution is of the form “x^(-k+1)” (ie. proportional to the integral of “x^-k”). I repeated this exercise by manually sampling an inverse power law using the inversion method, only to get exactly the same result. Is anyone aware of the cause of this problem? It’s hard to think of an explanation that would result in the observed behaviour - that the distribution resulting from such a sampling is a power law with an index increased by exactly 1.
Thanks for your help,
Max