How Random Number Generators Work (and How to Pick Numbers Fairly)
Whether youโre drawing a raffle winner or sampling data for research, fairness depends on how your random numbers are made. Hereโs what happens behind the button โ and how to use it well.
Pseudo-random vs cryptographic
Most programming languagesโ default generators (like JavaScriptโs Math.random()) are fast but predictable if someone knows the internal state. Cryptographically secure generators, like the Web Crypto API RandNow uses, draw on operating-system entropy and are suitable even for security purposes.
The hidden problem: modulo bias
Squeezing a large random value into a small range with the remainder operator slightly favours some numbers. RandNow uses 53 bits of randomness per draw and scales it, making every number in your range equally likely.
Practical recipes
- Raffle: min 1, max = tickets sold, 1 number.
- Lottery: 6 unique numbers from 1โ49, sorted ascending.
- Random sample: unique numbers to select rows from a dataset.
- Dice simulation: 1โ6 with duplicates allowed.
Pro tips
- Screen-record the draw for transparent giveaways.
- Turn on โNo duplicatesโ for any lottery-style draw.
- Use the sum and average shown to sanity-check large batches.