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)

To remove "0's" i wrote:
n=1000000
x=floor(runif(n,0,37)*100)/100
hist(x,breaks=37)
What gave me

And my question is why it works?
No, it's not a problem with runif.
Try this instead:
plot(density(x))
and you see the distribution is smooth
the issue is with where the breaks in your histogram are being placed, and that there's a fencepost problem at work. Histogram is not the best visualization tool for this, because basically the breaks have to line up perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With