Deterministic Replay of a Random Experiment
A recorded seed and a compatible generator can reproduce a pseudo-random sequence. The sequence of calls matters as much as the seed.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Track a consumed draw
A three-draw simulation can change its third result after new code makes one extra call for diagnostics. A state trace of random draws can reveal where the shared generator diverged.
Preserve concrete failures
Keep a copy of the generated example as well as the generator setting when it exposes a defect. Version and call order can change later. See deterministic random tests for replaying such cases.[1]
Record the run identity as well as the initial seed
A test shuffles twenty fixed records and fails on only one permutation. Keeping the original ordered input and the seed makes it possible to rerun the same shuffle with the same generator and implementation. An extra random call before shuffling may change the resulting order. See sequences of events.
Saved metadata: seed, generator name/version, initial records
Also preserve the failing order for an implementation-independent replay
Use a separate source for unrelated random choices
Distinguish a reproducible experiment from independent repetitions
Reinitializing the generator from the same seed produces repeated samples under fixed conditions. A simulation estimating uncertainty should vary seeds or use a controlled independent stream. Replay the failing sequence during debugging, then use fresh cases when measuring behavior.