logoalt Hacker News

wilbo • yesterday at 11:22 PM • 2 replies • view on HN

I got lost when OP talked about using 10 integers to choose from 3 choices. I think I figured out what was missing in the explanation.

random_u64() Mod 3 does indeed have a single bucket that is oversized. This overweights one option by about 5×10^-20.

rand() Itself has only 32767 possible values, so it's also common for a bucket to be overweighted depending on the number of buckets.


Replies

incompatible • yesterday at 11:42 PM

Makes you wonder at what point overweighting by about 5×10^-20 is something you'd want to care about.

➕ show 1 reply
omoikane • today at 3:13 AM

> rand() Itself has only 32767 possible values

For MingW maybe (due to MSVCRT). I think most libraries such as glibc have RAND_MAX at 2147483647.