jeudi 26 octobre 2017

Power law random number generator mirror image histogram

I'll be happy to erase this question hopefully after getting some tips. I am trying to follow this post to generate power-law distributed values following the equation from Wolfram MathWorld:

enter image description here

I used R, although the code could be easily translated into any other language:

x1 = 8
x0 = 0
n = 2.5
y = runif(1e5)
x = ((x1^(n+1) - x0^(n+1))*y + x0^(n+1))^(1/(n+1))
hist(x)

enter image description here

yielding a histogram symmetrical to what I expected.

What am I missing?




Aucun commentaire:

Enregistrer un commentaire