flopscope.numpy.random.Generator.spawn
fnp.random.Generator.spawn(self, n_children)[flopscope source]
Create new independent child generators.
Adapted from NumPy docs np.random.Generator.spawn
Cost
0
Flopscope Context
Returns child Generators; subclass override wraps them as _CountedGenerator.
See seedsequence-spawn for additional notes on spawning children.
Added in version 1.25.0.
Parameters
- n_children:int
Returns
- child_generators:list of Generators
Raises
- :TypeError
When the underlying SeedSequence does not implement spawning.
See also
- random.BitGenerator.spawn Equivalent method on the bit generator and seed sequence.
- random.SeedSequence.spawn Equivalent method on the bit generator and seed sequence.
- bit_generator The bit generator instance used by the generator.
Examples
Starting from a seeded default generator:
>>> # High quality entropy created with: f"0x{secrets.randbits(128):x}"
>>> entropy = 0x3034c61a9ae04ff8cb62ab8ec2c4b501
>>> rng = flops.random.default_rng(entropy)Create two new generators for example for parallel execution:
>>> child_rng1, child_rng2 = rng.spawn(2)Drawn numbers from each are independent but derived from the initial seeding entropy:
>>> rng.uniform(), child_rng1.uniform(), child_rng2.uniform()
(0.19029263503854454, 0.9475673279178444, 0.4702687338396767)It is safe to spawn additional children from the original rng or
the children:
>>> more_child_rngs = rng.spawn(20)
>>> nested_spawn = child_rng1.spawn(20)