How Random Number Generators Actually Work

PRNGs, seeds, cryptographic randomness and the gambler’s fallacy, explained in plain English.

Mustafa Bilgic
Mustafa BilgicFounder & tool-maker at Mohoh · last reviewed June 2026

Every time you tap our random number generator, dice roller or decision wheel, a number appears that you could not have predicted. But where does that number actually come from? The honest, fascinating answer is that most “random” numbers on a computer are not random at all — they are pseudo-random, and understanding the difference helps you trust (and correctly use) tools like these.

Computers are deterministic — so how do they get randomness?

A computer is a machine for following instructions exactly. Give it the same input and it gives you the same output, every time. That is wonderful for arithmetic and terrible for randomness. To produce numbers that look random, computers use a pseudo-random number generator (PRNG): a clever mathematical formula that takes a starting value (called a “seed”) and churns out a long, complex sequence of numbers that has no obvious pattern.

The role of the seed

The seed is the secret ingredient. Feed a PRNG the same seed and you get the exact same “random” sequence — which is why video games can replay the same level layout, and why scientists can reproduce experiments. To make results unpredictable, the generator is seeded from something hard to guess, such as the precise time, mouse movements, or hardware noise.

Pseudo-random vs cryptographically secure

Not all PRNGs are created equal. A basic one (like JavaScript’s Math.random()) is fast and fine for games, but its sequence can sometimes be predicted by someone who studies it. A cryptographically secure generator (CSPRNG) is built so that, even seeing many outputs, you cannot predict the next one. Browsers expose this through crypto.getRandomValues().

Mohoh deliberately uses your browser’s crypto.getRandomValues() wherever it is available. That is why our coin flips, dice and draws are genuinely unbiased and unpredictable — not the lazy shortcut many simple tools rely on. You can read more in our randomness explainer.

What “truly random” really means

True randomness comes from physical processes that are fundamentally unpredictable: radioactive decay, atmospheric noise, the thermal jiggle of electrons. Specialised hardware random number generators tap these sources. For everyday purposes — games, draws, picking a name — a good CSPRNG is statistically indistinguishable from true randomness, so the distinction rarely matters in practice.

The “gambler’s fallacy”: a trap to avoid

Here is the most important practical lesson. Each call to a fair generator is independent of the last. If you flip five heads in a row, the chance of heads on the sixth flip is still exactly 50% — the coin has no memory and is not “due” for tails. Believing otherwise is the gambler’s fallacy, and it trips up even smart people. Random streaks are normal and expected; they are not a sign the generator is broken.

How to know a generator is fair

A fair generator should produce every value in its range with equal probability over many trials, with no detectable pattern. Statisticians test this with tools that check the distribution is flat and the sequence is unpredictable. You can do a rough home version yourself: roll our dice a few hundred times and you should see each face come up roughly the same number of times.

Why this matters for you

Knowing how randomness works helps you use it well: trust a good generator for fairness, ignore “hot” and “cold” streaks, and reserve certified, audited systems for things that legally require them (like official lotteries). For everything else — from breaking a tie to running a friendly raffle — a solid browser-based generator like Mohoh’s is exactly the right tool.

Advertisement

Frequently asked questions

Are computer random numbers truly random?

Most are ‘pseudo-random’ — produced by a formula from a hidden seed. A good cryptographically secure generator (like the browser’s crypto.getRandomValues) is statistically indistinguishable from true randomness for everyday use.

What is a seed in a random number generator?

The seed is the starting value a generator uses to produce its sequence. The same seed always yields the same ‘random’ numbers, which is why unpredictable seeds (like the exact time or hardware noise) are used to make results unguessable.

If I roll five sixes, is a six less likely next time?

No. Each roll is independent, so the odds of a six are unchanged regardless of past rolls. Expecting otherwise is the ‘gambler’s fallacy’ — fair generators have no memory.