by wilbo · 1mo ago · 0 comments
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.
If the basic available function was rand_1_to_10(), modulo-ing its result by 3 would clearly make one result more probable than the others. The same happens with random_u64(); even though the difference is smaller, it can still be significant.
But in the case of the random_u64() mod 10, you would need the heat death of the universe number of samples before that bias would be noticeably distinguishable from random.
Is there an actual example of where that specific case could be significant for anything other than maybe nation-state cryptography?
For MingW maybe (due to MSVCRT). I think most libraries such as glibc have RAND_MAX at 2147483647.