numpy.random.SeedSequence
-
class numpy.random.SeedSequence(entropy=None, *, spawn_key=(), pool_size=4) -
SeedSequence mixes sources of entropy in a reproducible way to set the initial state for independent and very probably non-overlapping BitGenerators.
Once the SeedSequence is instantiated, you can call the
generate_statemethod to get an appropriately sized seed. Callingspawn(n)will createnSeedSequences that can be used to seed independent BitGenerators, i.e. for different threads.- Parameters
-
-
entropy{None, int, sequence[int]}, optional -
The entropy for creating a
SeedSequence. -
spawn_key{(), sequence[int]}, optional -
A third source of entropy, used internally when calling
SeedSequence.spawn -
pool_size{int}, optional -
Size of the pooled entropy to store. Default is 4 to give a 128-bit entropy pool. 8 (for 256 bits) is another reasonable choice if working with larger PRNGs, but there is very little to be gained by selecting another value.
-
n_children_spawned{int}, optional -
The number of children already spawned. Only pass this if reconstructing a
SeedSequencefrom a serialized form.
-
Notes
Best practice for achieving reproducible bit streams is to use the default
Nonefor the initial entropy, and then useSeedSequence.entropyto log/pickle theentropyfor reproducibility:>>> sq1 = np.random.SeedSequence() >>> sq1.entropy 243799254704924441050048792905230269161 # random >>> sq2 = np.random.SeedSequence(sq1.entropy) >>> np.all(sq1.generate_state(10) == sq2.generate_state(10)) True
- Attributes
-
- entropy
- n_children_spawned
- pool
- pool_size
- spawn_key
- state
Methods
generate_state(n_words[, dtype])Return the requested number of words for PRNG seeding.
spawn(n_children)Spawn a number of child
SeedSequences by extending thespawn_key.
© 2005–2020 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/1.19/reference/random/bit_generators/generated/numpy.random.SeedSequence.html