Productivity ToolsRandom

Random Number Generators, Explained

What "random" really means on a computer, the hidden bias in naïve generators, and how to draw a genuinely fair winner.

What "random" means on a computer

Computers are deterministic machines — they do exactly what they are told, the same way every time. That makes generating true randomness surprisingly hard. Most "random" numbers you encounter are actually pseudo-random: produced by an algorithm that starts from a seed value and generates a long, complicated sequence that only looks unpredictable. Give the algorithm the same seed and it produces the same sequence every time. For shuffling a music playlist this is fine; for anything where fairness or security matters, it is not enough.

The gold standard for everyday fairness is a cryptographically secure pseudo-random number generator (CSPRNG). In the browser this is crypto.getRandomValues, which mixes in entropy the operating system gathers from unpredictable physical events — timing jitter, hardware noise, input events. It is designed so that even knowing every previous output, you cannot predict the next one. That property is exactly what you want for a raffle, a giveaway, or a game. TheRandomizeruses this source for every mode.

Why Math.random isn't good enough for draws

The familiar Math.random() returns a floating-point number between 0 and 1, but the specification does not require it to be cryptographically secure — and in practice it is not. Its internal state can sometimes be reconstructed from a handful of outputs, and its distribution has known weaknesses in some engines. For a decorative animation none of this matters. For choosing a prize winner in public, or anything where someone might benefit from predicting or challenging the result, a secure generator removes the doubt.

There is a second, more subtle problem that affects even secure sources if you use them carelessly: modulo bias.

The hidden trap: modulo bias

Suppose you have a random 32-bit integer (a value from 0 to about 4.29 billion) and you want a number from 1 to 100. The obvious approach is to take the remainder: value % 100 + 1. It looks fair, but it is not quite. 4,294,967,296 does not divide evenly by 100 — there is a remainder of 96. That means the numbers 1 through 96 each have one extra chance of coming up compared with 97 through 100. The bias is tiny here, but it grows as the range gets larger relative to the source, and for something billed as "fair," any bias is a flaw.

The fix is rejection sampling. You compute the largest multiple of your range that fits inside the source's maximum, and simply throw away (reject) any random value above that cut-off, drawing again. Because you only accept values from a range that divides evenly, every outcome becomes exactly equally likely. The occasional re-draw costs almost nothing, and the result is provably unbiased. The Randomizer does this for every number, die and coin it produces.

ApproachFair?Good for
Math.random × rangeNo (insecure + biased)Animations, toys
Secure source + moduloAlmost (slight bias)Casual games
Secure source + rejection samplingYesRaffles, giveaways, draws

Shuffling fairly: the Fisher-Yates method

Picking a random order for a list — the basis of the list picker's "shuffle" and of any lottery-style draw — has its own classic pitfall. The naïve approach of "sort by a random comparator" produces uneven, biased orderings in most sort implementations. The correct algorithm is the Fisher-Yates shuffle: walk through the list from the last item to the first, and swap each item with a randomly chosen one at or before its position. Done with an unbiased random source, every one of the possible orderings is exactly equally likely.

This is why the "no repeats" number mode and the list shuffler are trustworthy for real draws: they build the full pool, shuffle it with Fisher-Yates, and take what they need. Nobody can be favoured, and no result can repeat within a single draw.

Dice, coins and the gambler's fallacy

A fair six-sided die gives each face a one-in-six chance on every roll, independent of what came before. A fair coin is 50/50 every flip. This independence is where the gambler's fallacy creeps in: after five heads in a row, it feels like tails is "due." It is not — the coin has no memory, and the sixth flip is still exactly 50/50. Over a large number of flips the ratio drifts toward 50/50 not because the coin corrects itself, but because early streaks are simply diluted by the growing sample.

Rolling multiple dice does change the shape of the results, though. Summing two six-sided dice makes 7 far more common than 2 or 12, because there are six ways to make 7 (1+6, 2+5, 3+4, …) but only one way to make 2. That bell-shaped distribution of sums is itself perfectly fair — it just reflects how many combinations produce each total. The Randomizer shows both the individual dice and their total so you can see this in action.

Everyday uses

Making a draw look fair, not just be fair

For public draws, being fair is only half the job — people also need to trust that it was fair. A few simple practices help: announce the rules and the range before you draw, do the draw live or on screen so everyone sees it happen, use "no repeats" so a name cannot win twice, and keep a record of the entries and the result. Because this tool runs entirely in your browser and touches no server, there is nothing hidden to distrust: what you see generated is exactly what the secure random source produced.

Pseudo-random vs truly random: the deeper story

It is worth pausing on what "random" can even mean for a machine. A pseudo-random generator is an algorithm: it starts from a seed number and produces a sequence that is deterministic but statistically unpredictable-looking. Every such generator eventually repeats — its period — and low-quality ones repeat sooner or reveal patterns. The cryptographic generator the tool uses avoids these pitfalls by continuously mixing in entropy that the operating system harvests from genuinely unpredictable physical events: the precise timing of keystrokes and disk activity, hardware noise, and interrupt jitter. That entropy is what makes its output unpredictable in practice, not just in appearance.

At the far end are true random number generators that sample physical randomness directly — thermal noise in a resistor, radioactive decay, or even a wall of lava lamps famously used by one company to seed its systems. For everyday fairness you do not need any of that exotic hardware; a well-seeded cryptographic generator is indistinguishable from true randomness for a raffle or a game, which is exactly why it is the right tool for the job.

Why real randomness looks "clumpy"

Here is a surprise that trips up almost everyone: genuinely random results look far less even than people expect. Ask someone to fake a coin-flip sequence and they will carefully alternate to avoid long runs — but real coins produce streaks of five or six heads regularly. True randomness clumps; it is human intuition that wrongly expects it to spread out neatly. This is why a shuffled playlist can seem to "favour" one artist (it isn't) and why a fair die can produce three sixes in a row (it will, sometimes).

The classic demonstration is the birthday problem. How many people need to be in a room before two of them probably share a birthday? Intuition says a large number; the answer is just 23. With 23 people there are 253 possible pairs, and it only takes one match, so the probability crosses 50%. By 70 people it is 99.9%. The lesson for random draws is practical: apparent "coincidences" (the same number twice, a surprising streak) are not evidence of a broken generator — they are exactly what real randomness produces. If you want to guarantee no repeats, that is what the "no repeats" mode and a proper shuffle are for.

Dice probabilities: what the numbers really are

A single fair die is uniform — every face has an identical 1-in-6 chance, and the long-run average of a six-sided die is 3.5. But the moment you roll and sum multiple dice, the distribution changes shape dramatically, because there are many more ways to make a middle total than an extreme one.

Sum of 2d6Ways to make itProbability
2 or 1212.8%
3 or 1125.6%
6, 7 or 85–6~14–17% each
7 (most likely)616.7%

Seven is the most common two-dice total for a simple reason: there are six different combinations that make it (1+6, 2+5, 3+4, and their reverses) but only one way each to make 2 or 12. This bell-shaped spread of sums is itself perfectly fair — it just reflects how many combinations produce each total — and it is the mathematical reason board games centre their odds around 7. The tool shows each individual die alongside the total so you can watch this play out roll after roll.

Seeds, reproducibility and audit trails

There is a useful distinction between randomness you want to be unpredictable and randomness you want to be reproducible. For a giveaway, unpredictability is everything — nobody, including you, should be able to know the result in advance, which is what a cryptographic source guarantees. But in other settings, being able to reproduce a sequence is the goal: a scientist running a simulation, or a developer testing code, wants the "random" numbers to be the same each run so results can be checked. They achieve that by fixing the seed — the starting value a pseudo-random generator grows its sequence from. Same seed, same sequence, every time.

For a public draw, reproducibility takes a different and clever form. Some transparent lotteries commit to a source of future randomness that nobody controls — a specific future stock-market close, or a published random beacon — and announce it in advance. Anyone can later verify that the winners were derived from that value, so the draw is both unpredictable beforehand and auditable afterward. You do not need that machinery for a classroom or a raffle, but it is a neat illustration of how "fair" and "verifiable" can be combined.

Three myths about randomness

Because our intuition about chance is so poor, a few persistent myths are worth naming directly:

The practical upshot is to trust the maths over the gut. If a fair generator surprises you, it is usually your intuition that is wrong, not the tool — and when you genuinely need a guarantee (no repeats, a fair ranking), the right mode gives you exactly that with certainty rather than luck.

Randomness is one of those things that seems simple until you look closely — and then turns out to hide real subtleties about bias, security and fairness. The good news is that the browser gives every page a genuinely strong random source, and with rejection sampling and a proper shuffle, a fair draw is only a click away. Try it in theRandomizer— numbers, dice, coins and name picks, all fair and all private.