numpy 1.22.4 Pypi GitHub Homepage
Other Docs
AttributesNotesParametersBackRef
MT19937(seed=None)

Attributes

lock: threading.Lock :

Lock instance that is shared so that the same bit git generator can be used in multiple Generators without corrupting the state. Code that generates values from a bit generator should hold the bit generator's lock.

Notes

MT19937 provides a capsule containing function pointers that produce doubles, and unsigned 32 and 64- bit integers . These are not directly consumable in Python and must be consumed by a Generator or similar object that supports low-level access.

The Python stdlib module "random" also contains a Mersenne Twister pseudo-random number generator.

State and Seeding

The MT19937 state vector consists of a 624-element array of 32-bit unsigned integers plus a single integer value between 0 and 624 that indexes the current position within the main array.

The input seed is processed by SeedSequence to fill the whole state. The first element is reset such that only its most significant bit is set.

Parallel Features

The preferred way to use a BitGenerator in parallel applications is to use the SeedSequence.spawn method to obtain entropy values, and to use these to generate new BitGenerators:

>>> from numpy.random import Generator, MT19937, SeedSequence
>>> sg = SeedSequence(1234)
>>> rg = [Generator(MT19937(s)) for s in sg.spawn(10)]

Another method is to use :None:None:`MT19937.jumped` which advances the state as-if $2^{128}$ random numbers have been generated (, ). This allows the original sequence to be split so that distinct segments can be used in each worker process. All generators should be chained to ensure that the segments come from the same sequence.

>>> from numpy.random import Generator, MT19937, SeedSequence
>>> sg = SeedSequence(1234)
>>> bit_generator = MT19937(sg)
>>> rg = []
>>> for _ in range(10):
...    rg.append(Generator(bit_generator))
...    # Chain the BitGenerators
...    bit_generator = bit_generator.jumped()

Compatibility Guarantee

MT19937 makes a guarantee that a fixed seed and will always produce the same random integer stream.

Parameters

seed : {None, int, array_like[ints], SeedSequence}, optional

A seed to initialize the BitGenerator . If None, then fresh, unpredictable entropy will be pulled from the OS. If an int or array_like[ints] is passed, then it will be passed to SeedSequence to derive the initial BitGenerator state. One may also pass in a SeedSequence instance.

Container for the Mersenne Twister pseudo-random number generator.

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.random.mtrand.RandomState

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/random/_mt19937.cpython-39-darwin.so#None
type: <class 'type'>
Commit: