The Hidden Bias in Your Random Number Generator

When random is not actually random enough

The Hidden Bias in Your Random Number Generator

Using modulo to pick a random item from a set seems harmless, but it skews the distribution: in a set of three, the first item gets picked 40% of the time instead of 33%. The author, who works with the Antithesis fuzzing platform, explains why random_u64() is too low-level and argues for a weighted random_choice() function that makes the desired distribution explicit and prevents subtle bugs.

The next time you see some code like the original sample, ask yourself: can I just represent the desired distribution directly?

More from this day

2026-10-06