Computer science
Randomness in computers
How a machine that computes strictly by rule can still roll dice: pseudorandomness, seeds and true randomness.
What you need first
In your favourite game the loot is never the same twice, the music app shuffles your playlist, and the enemies show up somewhere different every time. But wait: a computer follows rules strictly, and the same input always produces the same result. How can such a machine roll dice? The answer is a clever trick, and it sits inside almost every app you use.
Pseudorandomness: calculation that looks random
Computers are deterministic: same input, same result, every time. So they generate random numbers with a calculation rule, a so called pseudorandom generator. It starts from a starting value, the seed, and computes one number after another from it. The sequence looks wildly shuffled, but it is completely predetermined: same seed, same sequence. That sounds like a bug, but it is often an advantage: when testing you can repeat a failure exactly, and in games like Minecraft the same seed creates the same world within the same game version.
True randomness from measurements
Sometimes pseudorandomness is not enough, for example when nobody must be able to predict the numbers. Then computers tap into the real world: they measure tiny fluctuations, such as the noise in electronic components, the exact time gaps between your key presses or temperature flicker in the chip. A single key-press gap on its own is not good randomness yet. Only when a computer collects many such measurements as a source of entropy and a secure random generator turns them into numbers does unpredictable randomness emerge.
Randomness in games and encryption
In games, randomness keeps things exciting: dice rolls, shuffled cards, surprising enemies. Pseudorandomness is perfect here because it is fast and can be repeated for testing. With it is exactly the other way round: a secret key must be unpredictable, otherwise an attacker can reconstruct it. That is why passwords and encryption use true randomness, or at least mix it in as the seed.
Exercises
0 of 6 solvedTime to try it yourself. You can't break anything, every attempt counts.
Why can a computer not simply roll dice on its own?
A pseudorandom generator is started twice with the same seed. What happens?
A bag holds 4 red and 6 blue marbles. The computer draws one marble, and every marble is equally likely. What is the probability of red? Give the result as a decimal.
For a secret key you need … randomness, because nobody must be able to predict it.
A game draws a whole number from 1 to 10, all equally likely. What is the probability of exactly 7? Give the result as a decimal.
Match each term with its description.
Where this leads