Seeds and reproducibility
What a simulation's seed is, when two runs are identical, when they are valid but not identical, and how many different worlds there really are.
Many pages of the manual send you here with the same promise: “same seed, same simulation”. This page delivers on it and adds what usually gets lost along the way: what exactly that seed is, what is never repeated no matter how much you want it to be, and why two different seeds can give the same world.
What the seed is
The seed is the number that starts the world's random number generator. The engine doesn't roll dice: it uses a pseudorandom number generator, a machine that produces a very long sequence of numbers that looks random but is pure math. The seed is the point in that sequence where it starts.
Everything the engine draws comes from that single sequence, in order: where each seeded bot is born, where the scenario's obstacles and teleporters fall, which mutation comes out in each birth, where the vegetables the engine repopulates reappear, and the draws of each phase of the cycle (see The cycle and the order of actions). Since everything comes from the same sequence in the same order, changing the starting point changes the entire history.
Hence the rule you've read everywhere: the same scenario, with the same DNA in each species, and the same seed give the same simulation, cycle by cycle. Not “similar”: identical. The same positions, the same energy, the same births and deaths in the same cycles.
In the app the seed is an integer between 1 and 2147483646. You choose it when launching the simulation, in the right-hand column of Experiment, with a die (🎲, Another random seed) in case you want to draw one; the scenario doesn't store it (see Scenarios). Other places where it appears:
- each tournament match carries its own, noted in the Matches tab of Compete, and it is the one ↻ Replay reuses;
- the first replicate of a replicates job uses the source run's seed, to repeat it (see Analyze);
- the test of a bot (Test, in the editor) runs several seeds and, with the same first one, always gives the same result (see The DNA editor).
- the evolution (Evolve, in the editor) tests the base and each variant with the same replicate seeds, which come from the round's seed, as in Test. The variants are generated in disposable sims of the engine, each with the round's seed plus a number: the user's simulation isn't touched and uses no randomness (see The DNA editor).
When two runs are identical
The complete list of what has to match is short:
| Has to match | What it covers |
|---|---|
| The scenario | World parameters, species (which ones, how many, with what color), objects. |
| The DNA | That of each species: if the scenario references a bot by name, the same bot; the Bestiary is the same for everyone. |
| The seed | The starting point of the randomness. |
| The engine version | Between app versions some engine detail may change, and with it the run. |
If all four match, the two runs are the same, and it doesn't matter where: the same configuration in any browser, on your machine or a friend's, starts the same world and follows the same path.
The changes you make to a simulation live don't break anything: they are recorded with the cycle they came in at and are saved with the run. That is why a replicate can repeat your entire run, applying each change at its same cycle (see Experiment).
Valid but not identical: resuming
There is one case where a run is still valid but not identical to how it would have continued: resuming a saved run, or loading a .dbsim.
The file stores the world (bots, positions, energy, ties, the shots in flight), but not the random generator's exact position. On load, the app reseeds the randomness with the run's seed, as if the sequence started over. From there on everything is legal: the draws keep coming out fine, but from another place in the sequence, so the future isn't the one the run would have had if you had never saved it. It is the behavior of the original and of the classic interface, not a defect of the port. The metrics history, the events and the lineage don't go inside the file either: they stay with the saved run in the browser (File formats).
What is guaranteed: the same file loaded in any browser continues the same way. The load is always the same, so your run resumed here and on another machine takes the same path. The DNA of a species that the file doesn't carry is restored by looking up the bot by its name, and the few settings that the format doesn't store are always rewritten with the same value. The Bestiary's bots are in every browser; yours, export them first (see Your data).
In practice: to carry on tomorrow where you left off, resume without worry (Home). For someone else to repeat your run from the start, don't give them the .dbsim: give them the exported scenario and the seed (see the recipes below). How a run is saved and what the file holds is in Observe and File formats.
How many worlds there really are
The uncomfortable question: with 2,147,483,646 seeds to choose from, how many different worlds can the engine give you? The answer: 65,536.
The generator has a 24-bit internal state (16,777,216 values), but when a simulation starts only 16 of those bits come from the seed: the engine seeds the randomness by dividing the seed by 100 and mixing the bits of the result, and 16 bits survive that mixing. It is a legacy of the original that the port reproduces bit for bit. With 65,536 worlds, each one is shared on average by about 32,768 seeds.
That two “different” seeds give the same world is not unusual: among the first 20,000 seeds, 473 repeat another one's world. Some pairs, checked by running the engine: 12345 and 73151 give exactly the same run; so do 1234 and 66184, and 49 and 807. 12346, on the other hand, gives another world. Two twin seeds aren't “similar”: they are the same world, and if you compare them you'll be comparing a run with itself.
Within a run, the generator goes through its 16,777,216 states before repeating the first draw; since a simulation with a population consumes thousands of draws per cycle, you won't run out of sequence.
The app knows about this and has you covered:
- replicates and the sweep discard the seeds that would repeat a world already used, so that the band and the deviation don't come out narrower than they are (see Analyze);
- the comparison report warns when the two runs you are comparing start from the same world (see Reports);
- if you pick seeds by hand, it isn't enough for them to be different numbers: in a job of 64 replicates, 3.5% repeated some world without anyone noticing.
What the app guarantees
- Scenario + seed give the same run in any browser and in any thread of execution. An interrupted replicate restarts from scratch and gives the same result; a long run doesn't depend on the machine.
- Each tournament match carries its seed, so the background round gives the same result as playing it while watching, and ↻ Replay warns if something doesn't match (see Compete).
- Everything a run records travels with its seed: the saved run, the report, the data JSON, the replicates JSON (with each one's seed) and the tournament one. What you report can be verified by anyone with the scenario, the seed and the same version of the app.
- The same
.dbsimloaded anywhere continues the same way.
Recipes
| You want to | Do this |
|---|---|
| Repeat a run exactly | In Experiment, open the same scenario, type the same Seed and press New simulation. If the run had live changes, use Replicates in Analyze: the first one repeats the entire run, with its changes at the same cycle. |
| Replay a match | In Compete, Matches tab, ↻ Replay: same rules, entrants, seeding order and seed. |
| Compare worlds | Replicates in Analyze: up to 64 runs of the same scenario with seeds that don't repeat worlds, with mean, band and deviation. For two individual runs, check whether the report warns that the seeds give the same world. |
| Share your run | For someone else to follow it from where you left off: Save → Download .dbsim in Observe. For them to repeat it exactly from the start: Export the scenario and give them the seed too. |
| Test whether a result was luck | Run several seeds: replicates, or a parameter sweep with Seeds per value. If the same thing wins in most of them, it wasn't luck. |
The common questions about repeating are in Frequently asked questions. And if you wonder how the original program's random sequence is made to come out the same in a browser today, that story is in How the port is built and in Differences from the original 2.48.32.