distributions.spawn_seeds()

Generate multiple statistically independent random seeds.

Usage

Source

distributions.spawn_seeds(
    n_streams,
    main_seed=None,
)

This function creates a set of SeedSequence objects that are guaranteed to produce independent streams of random numbers. This is crucial for ensuring that multiple random number generators don’t produce correlated outputs, which could bias simulation results.

Parameters

n_streams: int

The number of independent seed sequences to generate. Must be a positive integer.

main_seed: Optional[int] = None
Master seed that determines all generated sequences. If None, a random entropy source is used, making results non-reproducible across runs. Providing a value enables reproducible sequences.

Returns

List[np.random.SeedSequence]
A list of n_streams SeedSequence objects that can be used to initialize random number generators with independent streams.

Notes

This approach is preferred over manually creating seeds because it uses NumPy’s entropy pool management to guarantee statistical independence between streams, avoiding subtle correlations that might occur with manually chosen seeds.

Examples

>>> seeds = spawn_seeds(3, main_seed=12345)
>>> rng1 = np.random.default_rng(seeds[0])
>>> rng2 = np.random.default_rng(seeds[1])
>>> rng3 = np.random.default_rng(seeds[2])