Permuted congruential generator (64-bit, PCG64)#

classnumpy.random.PCG64(seed=None)#

BitGenerator for the PCG-64 pseudo-random number generator.

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

A seed to initialize theBitGenerator. If None, then fresh,unpredictable entropy will be pulled from the OS. If anint orarray_like[ints] is passed, then it will be passed toSeedSequence to derive the initialBitGenerator state. One may alsopass in aSeedSequence instance.

Notes

PCG-64 is a 128-bit implementation of O’Neill’s permutation congruentialgenerator ([1],[2]). PCG-64 has a period of\(2^{128}\) and supportsadvancing an arbitrary number of steps as well as\(2^{127}\) streams.The specific member of the PCG family that we use is PCG XSL RR 128/64as described in the paper ([2]).

PCG64 provides a capsule containing function pointers that producedoubles, and unsigned 32 and 64- bit integers. These are notdirectly consumable in Python and must be consumed by aGeneratoror similar object that supports low-level access.

Supports the methodadvance to advance the RNG an arbitrary number ofsteps. The state of the PCG-64 RNG is represented by 2 128-bit unsignedintegers.

State and Seeding

ThePCG64 state vector consists of 2 unsigned 128-bit values,which are represented externally as Python ints. One is the state of thePRNG, which is advanced by a linear congruential generator (LCG). Thesecond is a fixed odd increment used in the LCG.

The input seed is processed bySeedSequence to generate both values. Theincrement is not independently settable.

Parallel Features

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

>>>fromnumpy.randomimportGenerator,PCG64,SeedSequence>>>sg=SeedSequence(1234)>>>rg=[Generator(PCG64(s))forsinsg.spawn(10)]

Compatibility Guarantee

PCG64 makes a guarantee that a fixed seed will always producethe same random integer stream.

References

State#

state

Get or set the PRNG state

Parallel generation#

advance(delta)

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

jumped([jumps])

Returns a new bit generator with the state jumped.

Extending#

cffi

CFFI interface

ctypes

ctypes interface