MichaelTJones / pcg

Go implementation of Melissa O'Neill's excellent PCG pseudorandom number generator
Apache License 2.0
59 stars 5 forks source link

Bias in Bounded func? #6

Closed vrde closed 3 years ago

vrde commented 3 years ago

The Bounded function calculates a threshold value that is -bound % bound:

https://github.com/MichaelTJones/pcg/blob/df440c6ed7ed8897ac98a408365e5e89c7becf1a/pcg32.go#L51-L62

I'm not sure if I'm missing anything obvious, but -bound % bound will always be 0. If that's the case the following if will always be true, so the random number r will suffer the modulo bias.

vrde commented 3 years ago

Nevermind, I now see that the behavior using uint instead of int is different.