package np

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `SeedSequence
]
type t = [ `Object | `SeedSequence ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val create : ?entropy:[ `Sequence_int_ of Py.Object.t | `I of int ] -> ?spawn_key:Py.Object.t -> ?pool_size:Py.Object.t -> unit -> t

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_state` method to get an appropriately sized seed. Calling `spawn(n) <spawn>` will create ``n`` SeedSequences 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 : nt, 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 : nt, optional The number of children already spawned. Only pass this if reconstructing a `SeedSequence` from a serialized form.

Notes -----

Best practice for achieving reproducible bit streams is to use the default ``None`` for the initial entropy, and then use `SeedSequence.entropy` to log/pickle the `entropy` for 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

val generate_state : ?dtype:Py.Object.t -> n_words:int -> [> tag ] Obj.t -> Py.Object.t

generate_state(n_words, dtype=np.uint32)

Return the requested number of words for PRNG seeding.

A BitGenerator should call this method in its constructor with an appropriate `n_words` parameter to properly seed itself.

Parameters ---------- n_words : int dtype : np.uint32 or np.uint64, optional The size of each word. This should only be either `uint32` or `uint64`. Strings (`'uint32'`, `'uint64'`) are fine. Note that requesting `uint64` will draw twice as many bits as `uint32` for the same `n_words`. This is a convenience for `BitGenerator`s that express their states as `uint64` arrays.

Returns ------- state : uint32 or uint64 array, shape=(n_words,)

val spawn : n_children:int -> [> tag ] Obj.t -> Py.Object.t

spawn(n_children)

Spawn a number of child `SeedSequence` s by extending the `spawn_key`.

Parameters ---------- n_children : int

Returns ------- seqs : list of `SeedSequence` s

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Stdlib.Format.formatter -> t -> unit

Pretty-print the object to a formatter.