mardi 29 décembre 2015

runif() is not uniform

I'm writing a roulette simulator and I stuck just on the beginning. I wanted to draw integer from 0 to 36, so I used runif(). I noticed that 0's are outstanding. Have a look:

n=1000000
x=floor(runif(n,0,37))
hist(x,breaks=37)

Histogram: floor(runif(n,0,37))

To remove "0's" i wrote:

n=1000000
x=floor(runif(n,0,37)*100)/100
hist(x,breaks=37)

What gave me Histogram: enter image description here

And my question is why it works?




Aucun commentaire:

Enregistrer un commentaire