therandomhomepage

A hand-kept directory of curious corners of the web, and notes on how chance works.

Top › Machines

How Random Number Generators Work

Computers are built to be predictable, which makes randomness surprisingly hard. There are two broad ways round the problem: clever arithmetic and physical noise.

Two families

Random number generation is the process of producing a sequence of numbers that cannot reasonably be predicted better than by chance. Generators fall into two broad families.

Pseudorandom generators

A pseudorandom number generator uses a deterministic algorithm. Start it from the same seed and it produces exactly the same sequence every time. That sounds like a flaw, but it is useful: scientists can rerun a simulation and get identical results, and games can rebuild the same level from a short code.

Hardware generators

A hardware random number generator draws on a physical process, such as electrical noise in a circuit, which is unpredictable in practice. These are often used to seed a pseudorandom generator rather than to produce every number directly.

Good enough for what?

  • Shuffling a playlist needs little more than an ordinary generator.
  • Scientific simulations need generators with good statistical properties.
  • Passwords and encryption keys need cryptographically secure generators, designed so that seeing earlier output does not help an attacker guess the next.

Random does not mean evenly spread

Real random sequences contain streaks and clumps. When a music app's shuffle plays two songs by the same artist in a row, that is often simply what randomness looks like. More on why our intuition gets this wrong in the gambler's fallacy.

filed 2026-10-22