MWC192X

class randomgen.mwcx.MWC192X(seed=None)

Container for the MWC192X pseudo-random number generator.

Parameters:
seed=None

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.

lock

Lock instance that is shared so that the same bit 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.

Type:

threading.Lock

seed_seq

The SeedSequence instance used to initialize the generator if mode is “sequence” or is seed is a SeedSequence.

Type:

{None, SeedSequence}

Notes

MWC192X is a multiply-with-carry generator with 64-bit digits, lag two, and period approximately \(2^{191}\), whose output is scrambled by X. It is the suggested generator of the family for 64-bit outputs. Since it simulates a multiplicative congruential generator with prime modulus, it can be advanced by an arbitrary number of steps, also backward, in logarithmic time. See [1] for details.

MWC192X 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.

State and Seeding

The MWC192X state consists of two 64-bit digits and a 64-bit carry. It is seeded using a SeedSequence, which fills the whole state; the carry is set to one if the resulting state is not valid.

Parallel Features

MWC192X can be used in parallel applications by calling the method jumped which advances the state as-if \(2^{96}\) random numbers have been generated, or advance, which advances the state by an arbitrary number of steps. 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
>>> from randomgen import MWC192X
>>> bit_gen = MWC192X(1234)
>>> rg = []
>>> for _ in range(10):
...    rg.append(Generator(bit_gen))
...    # Chain the BitGenerators
...    bit_gen = bit_gen.jumped()

Compatibility Guarantee

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

Examples

>>> from numpy.random import Generator
>>> from randomgen import MWC192X
>>> rg = Generator(MWC192X(1234))
>>> rg.standard_normal()
0.123  # random

References

Seeding and State

seed([seed])

Seed the generator

state

Get or set the PRNG state

Parallel generation

advance(delta)

Advance the underlying RNG as-if delta draws have occurred.

jumped([iter])

Returns a new bit generator with the state jumped

Extending

cffi

CFFI interface

ctypes

ctypes interface

Testing

random_raw([size, output])

Return randoms as generated by the underlying BitGenerator