Permuted Congruential Generator 2.0 (64-bit Multiplier, DXSM Output)

class randomgen.pcg64.PCG64DXSM(seed=None, inc=None)

Container for the PCG-64 updated with a 64-bit mult using DXSM output func.

Pre-configured alias for PCG64 with variant=”dxsm” and mode=”sequence”. This bit generator will likely become the default in NumPy in the near future ([3]).

Parameters:
seed=None

Random seed initializing the pseudo-random number generator. Can be an integer in [0, 2**128), a SeedSequence instance or None (the default). If seed is None, then PCG64DXSM will used a SeedSequence initialized with system entropy to Seed the generator

inc=None

The increment in the LCG. Can be an integer in [0, 2**128) or None. If inc is None, then it is initialized using the same SeedSeuqnce used for seed.

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.

Type:

threading.Lock

seed_seq

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

Type:

{None, SeedSequence}

Notes

Random variates are generated by permuting the output of a 128-bit LCG

\[s_{n+1} = m s_{n} + i \mod 2^{128}\]

where \(s\) is the state of the generator, \(m\) is the multipler and \(i\) is the increment. The multipler is a 64-bit unsigned integer with good spectral properties. The output of the LCG is the permuted using the DXSM output function which is similar to an Xorshift ([1], [2]).

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

Supports the method advance to advance the RNG an arbitrary number of steps. The state of the PCG-64 RNG is represented by a 128-bit unsigned integer.

State and Seeding

The PCG64DXSM state vector consists of 2 unsigned 128-bit values, which are represented externally as Python ints. PCG64DXSM is seeded using a single 128-bit unsigned integer. In addition, a second 128-bit unsigned integer is used as the increment in the LCG.

Compatibility Guarantee

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

Examples

Parallel Features

PCG64DXSM can be used in parallel applications by calling advance with a different value on each instance to produce non-overlapping sequences.

>>> from numpy.random import Generator
>>> from randomgen import PCG64DXSM
>>> rg = [Generator(PCG64DXSM(1234, i + 1)) for i in range(10)]
>>> for i in range(10):
...     rg[i].bit_generator.advance(i * 2**64)

References

Seeding and State

seed([seed, inc])

Seed the generator

state

Get or set the PRNG state

Parallel generation

advance(delta)

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

jump([iter])

Not implemented.

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