When random is not actually random enough
- 2026-10-06 technical by Austin Seipp There is a common pattern you see pop up in codebases everywhere that many of us have written: given a set of objects, pick one at random.
- Every object should have the same chance of being picked.
- A rather simple and direct solution is to pick a big random number, then clamp that number to the number of choices by modulo: Set<T> choices = ten_things(); u64 r = random_u64(); // uniform chance over [0..
Unverified
- 2026-10-06 technical by Austin Seipp There is a common pattern you see pop up in codebases everywhere that many of us have written: given a set of objects, pick one at random.
- Every object should have the same chance of being picked.
- A rather simple and direct solution is to pick a big random number, then clamp that number to the number of choices by modulo: Set<T> choices = ten_things(); u64 r = random_u64(); // uniform chance over [0..
Sources: Ersc