5 ms·
Are you sure? Maybe this isn't a good test but it seems pretty evenly distributed to me: https://go.dev/play/p/IeJQEAclBCU https://go.dev/play/p/IeJQEAclBCU E
by infogulch 2y 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 https://go.dev/play/p/IeJQEAclBCU
Edit: maybe this shows the bias better: https://go.dev/play/p/3eKJibIlF1a https://go.dev/play/p/3eKJibIlF1a
- cmeacham98 2y agoUInt32Max (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.
- infogulch 2y agoThat 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?
- codeflo 2y agoWhy would you need to “see” it? Unlike the distribution of the RNG itself, this is trivial to solve analytically.