How do computers make random numbers?
Most programs do not use true randomness. They use a pseudo-random number generator: a formula that turns one number into the next in a way that looks random but is completely determined. The first number is the seed. Give the generator the same seed and it produces the same sequence every time.
A tiny example shows the idea. Take the rule x(next) = (5x + 3) mod 16: multiply by 5, add 3 and keep the remainder after dividing by 16. Starting from the seed 7, it produces 7, 6, 1, 8, 11, 10, 5, 12, 15, 14, 9, 0, 3, 2, 13, 4 and then 7 again. It visits all sixteen values before repeating, in an order that looks jumbled, yet nothing about it is random. This kind of formula is called a linear congruential generator; real generators use far larger numbers and better mixing, so that their output passes statistical tests and repeats only after an astronomically long time.
Pseudo-random generators are made for simulations and games, not for secrets. Passwords and encryption keys need a cryptographically secure generator, designed so that nobody can predict the next number even after seeing many earlier ones.
What does a seed do in a simulation?
Every random-looking choice in a simulation, such as the exact launch angle of a ball, the order in which obstacles appear or which way a contestant turns, can be drawn from the generator. Because the generator is seeded, the whole run is fixed by the seed and the settings. Change nothing and you get the same run again; change the seed and every random choice changes with it.
That is what the Repeatable seed setting does in games such as Marble Race, Ring Escape and Line Arena. Its range, 0 to 2,147,483,647, allows 2,147,483,648 different seeds, which is 2³¹. Marble Race is a seeded 3D race: the same seed and settings replay the same race, so you can preview runs, keep the seed of a good one and record exactly that run.
The word settings matters. A seed is not a recording; it is the starting point of a calculation. If anything that affects the motion changes, such as the speed, the number of contestants or the size of the arena, the calculation takes a different path and the run is different, even with the same seed.
What is chaos?
A system is chaotic when it is deterministic, with no randomness at all, yet so sensitive to its starting point that tiny differences grow until the outcomes have nothing in common. A pinball, a double pendulum and the weather are chaotic. So is almost any simulation with many bouncing objects, because every collision turns a small difference in angle into a larger one.
The logistic map is the classic small example. Take a number x between 0 and 1 and repeatedly replace it with 4x(1 − x). Start one copy at 0.2 and another at 0.2000001, a difference of one in ten million. The table below follows both, computed in ordinary double-precision arithmetic and rounded to four decimal places.
For the first ten steps the two copies agree to three decimal places. By step 20 they differ in the first decimal, and from then on they are unrelated. The gap roughly doubles at every step, so a difference of one in ten million needs only about 23 doublings to become as large as the numbers themselves (2²³ is about 8.4 million).
Two starts one ten-millionth apart in the logistic map| Step | Starting at 0.2 | Starting at 0.2000001 | Gap |
|---|
| 0 | 0.2000 | 0.2000 | 0.0000001 |
|---|
| 5 | 0.5854 | 0.5854 | 0.0000039 |
|---|
| 10 | 0.1478 | 0.1479 | 0.000091 |
|---|
| 15 | 0.0039 | 0.0045 | 0.00053 |
|---|
| 20 | 0.8200 | 0.7095 | 0.11 |
|---|
| 25 | 0.9864 | 0.3519 | 0.63 |
|---|
| 30 | 0.3203 | 0.9903 | 0.67 |
|---|
How fast do small differences grow?
In a chaotic system the gap between two nearby runs grows roughly exponentially, multiplying by about the same factor in each unit of time. Scientists summarise the rate with a number called the Lyapunov exponent; for the logistic map above, the gap doubles per step on average. Its practical meaning is a horizon. If you know the starting point to a certain precision, you can predict the system only for a limited time, and every tenfold improvement in precision buys only a fixed amount of extra time.
This is why weather forecasts lose their skill after a week or two however good the computers get, and why nobody can call a marble race by eye from the first frame. In a simulation with dozens of collisions, a difference in the last decimal place of one ball's position can decide the winner a minute later.
Not every simulation is chaotic. A single ball bouncing on a flat floor is predictable: a small change in the drop height gives a small change in the result, and the error stays small. Chaos needs a way for differences to be stretched and folded back on themselves, which curved walls, collisions between moving objects and spinning obstacles all provide.
Can the same seed give different results on different computers?
It can, if the arithmetic differs even slightly. Computers store most numbers in binary floating point, which cannot represent many decimals exactly: 0.1 + 0.2 comes out as 0.30000000000000004. The order of operations matters as well. Adding 1 to 10,000,000,000,000,000 and then subtracting 10,000,000,000,000,000 gives 0, because the 1 is lost in rounding, while subtracting first and then adding 1 gives 1.
In a chaotic simulation, such last-digit differences behave like a changed seed: they grow until the run is different. Functions such as sine, cosine and powers can return results that differ in the last bit between systems, and two processors may combine operations differently. Developers who need identical runs everywhere keep the core arithmetic to simple, exactly specified operations, fix the order of calculations and sometimes use whole-number arithmetic instead of floating point.
Time steps matter for the same reason. If a simulation advances by however much time passed since the last frame, a slower device takes different steps from a faster one and the runs drift apart. Advancing by the same small step every time, and drawing frames separately, keeps the calculation identical whatever the frame rate.
Is a seeded race fair?
A seeded race is fair in the sense that the rules treat every contestant the same and nobody steers the result while it runs. But whoever sets it up can preview many seeds before recording, and in a chaotic race each seed can have a different winner. Picking the seed after watching the outcome is the same as choosing the winner.
That is fine for entertainment, as long as you do not present it as something else. If you ask viewers to predict the winner and you chose the seed knowing the result, do not claim that the race was decided live or by chance. Honest options include recording the first seed you try, naming the seed and settings in the caption so that the run can be replayed, or simply presenting the clip as a show rather than a contest.
Seeds also make good series. Rerunning a race with the same seed and one setting changed shows chaos directly: a small change at the start, possibly a different winner at the end. Naming the seed shows that the comparison is genuine.
Where else do seeds and chaos show up?
Seeds are everywhere in computing: generated game worlds, shuffled playlists, scientific simulations that must be rerun for checking, and machine learning experiments that fix the seed so that results can be reproduced. Chaos turns up in dripping taps, in turbulent fluids, in some heart rhythms and in planetary orbits over very long times. The common lesson is that determinism and predictability are not the same thing.
To see sensitivity for yourself, preview Marble Race with one seed and note the winner, then step through the next few seeds with every other setting unchanged and watch how the race changes.
Games for this guide
Marble Race: Named marbles race down a wooden, neon or candy track; keep the seed to replay the same race with new names.
Ring Escape: A small ball slips out through the gaps of up to 150 rotating rings while the camera zooms out.
Line Arena: Balls fan coloured lines in a shrinking ring and steal rival lines: flags, sports teams, your names or photos.
Video makers for this
Questions
What is a random seed?
The starting value of a pseudo-random number generator. The same seed produces the same sequence of numbers, so a simulation that draws its random choices from that generator replays the same run.
Is a seeded simulation really random?
No. It is deterministic: the seed and the settings fix every step. It only looks random because the generator scrambles numbers well and the seed is usually picked arbitrarily.
Why does changing one setting change the whole run?
Because the simulation is a chain of calculations. Change one input and every later step uses different numbers; in a chaotic system those small differences grow until the outcome is completely different.
What is the butterfly effect?
A popular name for sensitive dependence on initial conditions: in a chaotic system a tiny change at the start, like the flap of a butterfly's wing in the famous metaphor, can lead to a large difference later.
Is it fair to choose a seed after previewing it?
It is fine for entertainment, but choosing the seed after seeing the result means choosing the winner, so do not present such a clip as a live or chance result.