Hacker News new | ask | show | jobs
by infogulch 782 days ago
Are you sure? Maybe this isn't a good test but it seems pretty evenly distributed to me:

https://go.dev/play/p/IeJQEAclBCU

Edit: maybe this shows the bias better: https://go.dev/play/p/3eKJibIlF1a

1 comments

UInt32Max (i.e. 4294967295) is divisible by 3, so your code actually is perfectly random (or more accurately, as random as go's rand package). It would be biased with N=4, for example.

Regardless, with small values of N, the bias is very slight so you would need many many iterations to see the imperfection in a statically significant way.

That makes sense.

A quick search didn't reveal any good resources for how to test the quality of a random number generator in a number range. Is what I came up with the best strategy, and you just need to run it for much longer (and compare to a known-good implementation) to see the difference?

Why would you need to “see” it? Unlike the distribution of the RNG itself, this is trivial to solve analytically.