Your first simulationLesson 05 of 76 · 6 min
Reproduce a random run
Use seeds without confusing reproducibility with independent replication.
A pseudo-random generator produces a deterministic sequence from an initial state. A seed makes that state reproducible. Record the generator, package version, seed and draw order when you need someone else to recreate a calculation.
Two generators initialised with the same seed produce the same sequence under the same implementation. They are useful for replaying an experiment, but are not independent replications. Changing the sequence of calls changes which draws enter each calculation.
A fresh seed can reveal numerical variation under the same model. It cannot reveal assumptions omitted from that model. For parallel work, independent child streams, separate pseudo-random sequences, provide a principled alternative to repeatedly reusing one seed; the reproducibility module returns to that design.
- Same seed + operations
same random sequence
- Replay the calculation
same estimate
- Independent replication
a fresh random stream
Do two generators with the same seed provide two independent sets of evidence?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
Original: [74 84 10 16 45 55 76 36] Replay: [74 84 10 16 45 55 76 36] Different seed: [89 39 21 71 86 28 36 8] Replay identical: True
Read the first result
Compare the arrays in Original and Replay and read Replay identical. Those generators used the same seed. The Different seed row uses seed 18.
Try an edit
Add replay.integers(0, 100) immediately before b = replay.integers(0, 100, 8). Select Run Python again. Compare Original with Replay and read Replay identical. Why does the extra call change the replay even though its seed stays 17?
Scope. Identical seeds alone do not guarantee identical results across changed generators, package versions or draw ordering.
Try a fresh case
A colleague reruns your exact seeded simulation and obtains the same output. What was checked?
Need a hint?
Hint 1
Ask what changed between the two runs.
Hint 2
Distinguish replaying a sequence from obtaining a new one.