A team running many robot simulations may want each scenario to draw its own synthetic disturbances while remaining reproducible on a retry. If every task starts an identical generator from the same seed, the tasks begin with identical draws. If tasks instead draw from generators tied to workers, a change in scheduling can give the same scenario a different sequence. The task identity and the worker identity answer different questions.
The examples below were checked with NumPy 2.5.2 and explicitly use PCG64. The output is a set of invented integer samples. The fixture verifies stream assignment and repeatability in one environment. It does not measure a robot or establish that a particular disturbance distribution represents a physical sensor.
See what identical initialization does
Create a fresh generator from a seed and draw five integers between zero and 99. Repeat the procedure with the same seed and parameters. The second generator starts where the first generator started and returns the same five values. If a batch of nominally independent scenarios uses this pattern, the equality originates in setup. It is not evidence that the scenarios experienced different random draws but happened to agree.
from numpy.random import Generator, PCG64, SeedSequence
root_seed = 20261128
def five_draws(seed_sequence):
rng = Generator(PCG64(seed_sequence))
return rng.integers(0, 100, size=5).tolist()
first = five_draws(SeedSequence(root_seed))
second = five_draws(SeedSequence(root_seed))
assert first == second == [2, 90, 71, 67, 97]
The equality can be useful when the aim is to replay a scenario exactly. It can also be intentional when comparing two methods on a shared set of exogenous inputs. Those are different experimental choices from simulating separate replicates drawn from different streams. Record which comparison the run is meant to support.
Spawn children from one parent
NumPy's SeedSequence can derive child seed sequences from a shared parent. Each child gets a position in the spawning tree, and that position contributes to the initial state of its generator. NumPy describes these streams as independent with very high probability. Checking that two short lists are different is a diagnostic for this fixture, rather than a statistical test of the generators.
parent = SeedSequence(root_seed)
children = parent.spawn(2)
assert [s.spawn_key for s in children] == [(0,), (1,)]
assert [five_draws(s) for s in children] == [
[82, 63, 41, 0, 15],
[7, 19, 97, 34, 0],
]
assert parent.spawn(1)[0].spawn_key == (2,)
A coordinator can assign one child to each scenario and record the assignment before dispatch. If it builds a fresh parent from the saved seed, the first spawn returns the original child positions again. If it calls spawn again on the existing parent, the child positions continue. Replaying a particular scenario therefore uses the original assignment, while scheduling a new scenario can use a new child.
Keep the scenario ID independent of execution order
Suppose scenarios 17 and 42 originally ran in that order. In a later batch, scenario 42 runs first and scenario 8 is added. If stream positions are assigned by enumeration of the current task list, earlier assignments can move. Preserve a mapping from scenario ID to the original child, or build the stream from a stable, documented scenario key.
The following fixture uses the SeedSequence spawn_key parameter explicitly to illustrate the second method. Its dedicated seed tree reserves the single-element keys for scenario numbers. Do not also assign those positions by order-based spawning under the same root, because that could reuse an existing key.
def draw_for_scenario(scenario_id):
seed = SeedSequence(root_seed, spawn_key=(scenario_id,))
return five_draws(seed)
before = {sid: draw_for_scenario(sid) for sid in [17, 42]}
after = {sid: draw_for_scenario(sid) for sid in [42, 8, 17]}
assert before[17] == after[17] == [2, 91, 71, 6, 25]
assert before[42] == after[42] == [52, 21, 13, 45, 36]
Here the scenario IDs are stable nonnegative integers. A task retried from its beginning should reuse its ID if it is intended to produce the same draws. For new replicates within one scenario, define a separate index for each replicate and save it with the scenario ID. If a simulation resumes midway, it also needs the generator state at the checkpoint or a way to repeat the same sequence of draws through that point.
Save the details that make replay possible
Store the root seed, the scenario mapping or key scheme, the bit generator, and the NumPy environment with the simulation settings. Changes in sampling calls can change what later parts of a scenario draw, even when the initial seed matches. NumPy's compatibility policy describes repeatability under specific conditions that include the generator, method calls, arguments, build, and environment. The fixture above fixes the number and range of draws so it checks the intended mapping directly.
For example, one controller might stop a simulation early after a fault, while another continues. Starting both controllers with the same seed can reproduce their initial draws, but it does not ensure that a later draw represents the same event in both executions. A recorded disturbance trace indexed by simulation time gives both methods the same external input at each shared step. Treat internal controller randomness as a separate input when it has a different role in the comparison.
A regression test can reorder tasks, insert a new scenario, and rerun a saved scenario independently. Compare draws by scenario ID across those runs. Record the random inputs separately if a later comparison must survive changes to the simulation's draw order. That preserves the identity of the tested scenario and lets changes in controller behavior be evaluated against a known set of inputs.
Sources checked November 28, 2026
NumPy, Parallel random number generation
https://numpy.org/doc/stable/reference/random/parallel.html
NumPy, numpy.random.SeedSequence
https://numpy.org/doc/stable/reference/random/bit_generators/generated/numpy.random.SeedSequence.html
NumPy, Random compatibility policy
https://numpy.org/doc/stable/reference/random/compatibility.html
Illustration. AI-generated concept showing one root seed branching into two scenario streams on a robot simulation display.