Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

runif() is not uniform [duplicate]

Tags:

random

r

gambling

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?

like image 551
KryptonLC Avatar asked Dec 13 '25 14:12

KryptonLC


1 Answers

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.

like image 194
Shape Avatar answered Dec 15 '25 03:12

Shape



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!