ELI5: How do computers generate random numbers?

Explained with a strict baker

Computers generate random numbers either by following complex math recipes that pretend to be random, or by listening to the messy, unpredictable noise of the real world around them.

Because computers are designed to follow rules perfectly, being truly random is very hard for them. Think of a computer like a strict baker who must follow a recipe down to the last grain of sugar. If the baker follows the exact same steps, the cake tastes identical every time.

To create surprises, computers use two different methods:

  • The Math Trick (Pseudo-Random): Most of the time, like when you play a simple video game or shuffle a music playlist, the computer uses a clever math formula. To start, it grabs a starting number called a seed, which is often the exact millisecond on the computer's internal clock. It takes that time, runs it through a wild blender of math equations, and spits out a number. It looks completely random to us, but if you gave it the exact same starting time, it would give you the exact same result. It is like an enormous book of lottery numbers; the computer simply opens to a page based on the current second and reads the next number in line.
  • The Real-World Listener (True Random): Sometimes, "pretend" random is not safe enough, like when banks protect your credit card information. For these high-security jobs, computers look outside of their math rules and tap into the physical world using hardware randomness.

Just like you can look outside to see which way the wind blows, a computer can measure unpredictable things in its environment:

  • Tiny, microscopic changes in the heat of its chips
  • The exact, jittery timing between your finger taps on the keyboard
  • The tiny movements of your computer mouse
  • Static noise in electrical circuits, similar to the fuzzy hiss of an old television between channels

By gathering this unpredictable real-world chaos, the computer turns nature's messiness into truly random numbers that nobody can ever guess.

Ask your own question

Opens the question on the homepage. Nothing is sent until you press Explain it.

Follow-up questions

Test yourself

Three quick questions to see if it stuck. You can challenge a friend after.