Validate and communicateLesson 58 of 76 · 8 min
Give parallel runs independent streams
Create replayable child random streams without duplicating work.
A seed controls a generator’s initial state. Starting every worker from the same seed repeats the same sequence and does not provide independent simulation batches. Parallel execution needs a deliberate stream design.
NumPy SeedSequence can spawn reproducible child sequences intended for separate generators. Keep each child’s role and the parent seed recorded. Stream design is distinct from operating-system scheduling: this lesson creates the streams sequentially so the numerical behaviour remains inspectable.
When using chunks, avoid resetting a generator to the same state for every chunk. That would repeatedly recycle the same random inputs. Record enough metadata to reproduce the procedure, including package versions, algorithm, draw order and any changes in how workers receive streams.
- Record a parent seed
- Spawn child streams
- Replay the same spawn tree
same child sequences
What happens if every worker is initialised with exactly the same seed?
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 ↗
Child-stream first draws: [[629042, 382691, 176495, 20440], [748907, 671112, 646693, 157999], [88653, 550844, 899179, 233926], [465928, 743334, 802150, 178884]] Replay identical: True Spawn keys: [(0,), (1,), (2,), (3,)]
Read the first result
The child streams differ while the overall construction can be replayed. Different sample values alone would not prove arbitrary generators independent.
Try an edit
Add print("Same-seed batches:", [np.random.default_rng(2026).integers(0, 1000000, 4).tolist() for _ in range(4)]) immediately after print("Spawn keys:", [child.spawn_key for child in children]). Select Run Python again. Compare Same-seed batches with Child-stream first draws. How many distinct sequences are in each list?
Scope. The example illustrates stream construction without running actual parallel workers or claiming a parallel speedup.
Try a fresh case
Which record best supports replay of a multi-stream simulation?
Need a hint?
Hint 1
List what determines each worker’s random inputs.
Hint 2
Keep the assignment rule as well as the seeds.