01

Why randomness is needed

Random numbers are everywhere in computing. Games use them to shuffle cards and decide what an enemy does next. Scientists use millions of them in simulations of weather, traffic or financial risk. Music apps shuffle playlists, and lotteries and surveys pick winners and samples. Most importantly, security depends on them: the secret keys that encrypt your banking session, the codes in password-reset emails and the one-time numbers used in online logins must all be impossible to guess. Yet computers are designed to be predictable. Given the same input, a program produces the same output every time. Producing numbers that behave randomly from such a machine requires either clever mathematics or a link to physical chance.

02

Pseudo-random formulas

Most software uses a pseudo-random number generator, a formula that turns one number into the next in a way that looks patternless. It starts from a seed. A classic simple design multiplies the current number, adds a constant and keeps the remainder after division. With the toy rule 'multiply by 5, add 3, keep the remainder after dividing by 16', a seed of 7 produces 6, 1, 8, 11, 10, 5, 12 and so on, visiting all 16 values before repeating exactly. Real generators use far larger numbers and better formulas. The famous Mersenne Twister, published in 1998, repeats only after 2 to the power of 19,937 minus one numbers, and passes many statistical tests.

03

Same seed, same sequence

Determinism is useful. A scientist can rerun a simulation with the same seed and get identical results, which makes errors easier to track down. Games can recreate the same world from one short seed code. But predictability is fatal for security. Anyone who learns the seed, or observes enough outputs, can calculate every future number. In 1995 researchers showed that an early version of Netscape's secure web connection seeded its generator with the time of day and process numbers, which could be guessed, allowing encryption keys to be recovered. In 2008 a coding error in Debian Linux reduced the possible keys generated by one widely used security library to just 32,768.

04

Harvesting physical noise

Secure systems therefore gather entropy, the technical word for unpredictability, from the physical world. An operating system collects tiny timing variations in keystrokes, mouse movements, disk activity, network packets and hardware interrupts. Many modern processors include a hardware random number generator that samples electrical noise inside the chip. This raw entropy is mixed and used to seed a cryptographically secure pseudo-random generator, designed so that even someone who sees many of its outputs cannot work out past or future ones. Programmers are advised to use these operating-system services for anything security-related rather than the quick generators built into many programming languages, which are meant for games and simulations.

05

From dice tables to lava lamps

Before computers, people consulted printed tables. In 1955 the RAND Corporation published A Million Random Digits with 100,000 Normal Deviates, generated by an electronic roulette wheel and used by scientists for decades. Early computer pioneer John von Neumann proposed one of the first pseudo-random methods, while warning in 1951 that 'anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.' Inventive physical sources continue to appear. The internet company Cloudflare films a wall of lava lamps in its San Francisco office as one extra entropy input, and some laboratories and devices draw randomness from quantum effects such as the behaviour of individual photons.

06

Random is not uniform

People often misjudge randomness. Real random sequences contain streaks and clusters, so a shuffled playlist that plays two songs by one artist in a row can feel broken even when it is working perfectly; some services deliberately make shuffles less random to seem fairer. Lotteries and online games are audited because players cannot see the generator. Standards bodies such as the US National Institute of Standards and Technology publish requirements and test suites for random generators used in cryptography. As devices multiply, weak randomness remains a quiet risk, especially in small connected gadgets that start up identically and have little physical noise to gather. Good randomness is invisible until it fails.

FOLLOW THE EVIDENCE

Sources & further reading

Figures are rounded and widely published; check the linked organisations for the latest editions. These organisations do not endorse this website.