Is computer randomness really random?

Updated · 7 min read

A computer is a machine built to do exactly what it is told, the same way every time. That makes "pick a random number" a strange thing to ask of one. Give a program the same starting point and it will produce the same output, so where does the surprise come from?

The short answer is that there are three different things people mean by a random number generator, and they are not equally random. This guide explains each one in plain terms, says which one this site uses, and shows how you can test a generator yourself instead of taking anybody's word for it.

What "random" actually means

In everyday speech random means haphazard. In mathematics it means two specific things. First, every outcome has a known probability: on a fair ten-slice wheel, each slice has a 1 in 10 chance. Second, the results are unpredictable: knowing every earlier spin tells you nothing about the next one.

Those two properties are separate, and a generator can have one without the other. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, repeated for ever, gives every number exactly its fair share and is completely predictable. Most of the history of computer randomness is the story of generators that passed the first test and failed the second.

Pseudo-random generators: a recipe that looks like chance

A pseudo-random number generator, or PRNG, is a formula. It starts from a number called the seed, scrambles it to produce an output, and uses the scrambled state to produce the next one. The outputs look patternless, but they are fully determined by the seed. Run the same generator from the same seed and you get the same "random" numbers in the same order.

The idea is as old as electronic computing. In 1946 John von Neumann proposed the middle-square method: square a number, take the middle digits as your random number, and repeat. It works badly, because many seeds quickly collapse into short repeating loops or to zero. Von Neumann knew the philosophical problem too, remarking that anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.

Modern PRNGs are far better. The Mersenne Twister, the default in Python and many other languages, only repeats after 2 to the power of 19,937 minus 1 outputs, a number with about 6,000 digits. Most browsers use a fast generator called xorshift128+ for the ordinary Math.random function. Both spread their results very evenly, which is all a simulation or a video game needs.

Being repeatable is sometimes the point. A game such as Minecraft builds an entire world from one seed, so two players who type the same seed get the same world. Scientists record their seeds so that somebody else can rerun a simulation and get identical results.

Why "looks random" is not good enough

The weakness of an ordinary PRNG is predictability. Its internal state is small, and its outputs leak that state. Someone who sees 624 consecutive outputs of the Mersenne Twister can reconstruct its state and predict every number it will produce from then on. For a dice game with friends that does not matter. For a prize draw, a shuffled deck in online poker or a password, it is fatal.

Poorly designed generators can fail the evenness test as well. RANDU, a generator shipped with IBM mainframes in the 1960s, was used in scientific work for years before people noticed its flaw: plot three consecutive outputs as a point in space and every point falls on one of just 15 flat planes. Results that depended on it had to be treated with suspicion.

Secure generators: unpredictable in practice

A cryptographically secure generator, or CSPRNG, is still a formula, but it is built so that seeing any amount of its output does not help you guess what comes next, and it is seeded from genuinely unpredictable events rather than from the clock.

Your operating system collects that unpredictability all the time. It measures the exact timing of key presses, mouse movements, disk and network activity down to fractions of a microsecond, and most modern processors add a hardware source that samples electrical noise inside the chip. All of this is mixed into a pool, and the pool seeds the generator. This is the same machinery that creates the encryption keys protecting your bank login.

In a web browser it is available through a function called crypto.getRandomValues. Every wheel, coin, dice and team draw on this site uses it, not Math.random. Our guide to how online wheel spinners work describes how that random number becomes a winning slice.

True random: taking numbers from physics

A true random number generator has no formula at all. It measures a physical process that is unpredictable in itself and turns the measurements into numbers.

  • Atmospheric noise: random.org listens to radio static caused by distant lightning and other atmospheric activity.
  • Lava lamps: Cloudflare points a camera at a wall of lava lamps in its San Francisco office and feeds the ever-changing image into its key generation.
  • Radioactive decay: the moment an individual atom decays cannot be predicted, so the gaps between clicks of a detector are random.
  • Quantum effects: laboratory generators measure quantum behaviour such as fluctuations in a vacuum or which way a single photon goes at a half-silvered mirror. As far as physics can tell, these outcomes are not merely hard to predict but undetermined until they happen.

True generators are slower and need hardware, so in practice the two approaches are combined: a small amount of physical randomness seeds a secure generator, which then produces numbers as fast as anyone needs.

The three kinds side by side

Pseudo-randomSecure (CSPRNG)True random
Where numbers come fromA formula and a seedA formula seeded by physical eventsA physical measurement
Evenly spreadYes, if well designedYesYes, after correction
PredictableYes, from enough outputsNot in practiceNo
Repeatable from a seedYesNoNo
SpeedFastestFastSlow
Good forGames, simulationsDraws, passwords, encryptionSeeding the other two, lotteries

So is a wheel spin on this site truly random?

Strictly, it is the middle column. The number comes from a formula, so a philosopher would call it pseudo-random. But the formula is seeded from physical noise in your own device and is designed so that nobody, including us, can predict or reproduce it. For a raffle, a classroom pick or a game, there is no practical difference between that and a number drawn from lightning static.

One detail is worth knowing because it catches out a lot of home-made tools. Turning a random number into "a slice from 1 to 7" can introduce a small unfairness called modulo bias. Take a random byte, which is a number from 0 to 255, and reduce it to a number from 0 to 99 by taking the remainder after dividing by 100. The results 0 to 55 can each be reached three ways and 56 to 99 only two ways, so the low numbers come up half as often again. We avoid that by drawing a 53-bit fraction and scaling it, which leaves an unevenness of less than one part in a thousand million million: far too small for anybody to measure.

How to test a generator yourself

You cannot prove a sequence is random, but you can catch one that is not. The standard tool is the chi-square test. Run a large number of draws, count how often each outcome appeared, and compare the counts with what the probabilities predict. Small gaps are expected. The test tells you whether the gaps are the size chance normally produces or suspiciously large.

Every wheel on this site has this built in. Open the Odds tab on the random number wheel or any other wheel and run the fairness test: it performs up to 100,000 spins in a moment using the real generator and shows the actual share of each entry against the expected share, with the chi-square result underneath. Run it a few times. A fair wheel passes most runs and, by design of the test, looks unusual about one run in twenty. A generator that never looked unusual would itself be suspicious.

Why real randomness does not feel random

People are poor judges of chance. Ask a room to pick a number from 1 to 10 and 7 comes up far more than a tenth of the time, while 1 and 10 are avoided. Ask someone to write down an imaginary run of coin flips and they will switch between heads and tails too often, because a streak of five heads feels wrong even though streaks like that are common.

This is why a fair wheel sometimes seems broken. On a ten-slice wheel, any spin has a 1 in 10 chance of matching the one before it, so across an afternoon of use a repeat is close to certain. Music players ran into the same problem: listeners complained that shuffle was not random when it played two songs by one artist back to back, and several services changed their shuffle to be deliberately less random so that it would feel more so.

The belief that a result is "due" after a run of the opposite is called the gambler's fallacy. The wheel has no memory. Our guide asking is a coin flip really 50/50 looks at streaks in more detail.

Frequently asked questions

Are computer-generated random numbers truly random?

Most are pseudo-random: produced by a formula from a starting seed. A secure generator seeds that formula from unpredictable physical events in the device, which makes the output unpredictable in practice. Only hardware that measures a physical process is random in the strict sense.

What is the difference between Math.random and crypto.getRandomValues?

Math.random is a fast pseudo-random generator meant for games and animation, and its future outputs can be worked out from past ones. crypto.getRandomValues is a cryptographically secure generator seeded by the operating system. This site uses crypto.getRandomValues for every result.

What is a seed in a random number generator?

The seed is the starting value of a pseudo-random generator. The same seed always produces the same sequence, which is useful for reproducing a simulation or a game world and dangerous if the seed can be guessed.

Is quantum randomness better than computer randomness?

It is random in a deeper sense, because quantum outcomes are not determined in advance. For everyday draws it makes no measurable difference: a secure generator is already impossible to predict in practice.

Why does my wheel keep landing on the same result?

Repeats and streaks are a normal part of randomness. On a ten-slice wheel the chance that any spin matches the one before it is 1 in 10, so over a few dozen spins a repeat is almost certain.

Try these next

More guides