Permuted Congruential Generator (32-bit, PCG32)¶
0, *, mode=
Container for the PCG-32 pseudo-random number generator.
Random seed initializing the pseudo-random number generator. Can be an integer in [0, 2**64], a SeedSequence instance or
None(the default). If seed is
PCG32will try to read data from
/dev/urandom(or the Windows analog) if available. If unavailable, a 64-bit hash of the time and process ID is used.
The increment in the LCG. Can be an integer in [0, 2**64] or
None. The default is 0. If inc is
None, then it is initialized using entropy.
The seeding mode to use. “legacy” uses the legacy SplitMix64-based initialization. “sequence” uses a SeedSequence to transforms the seed into an initial state. None defaults to “sequence”.
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.
The SeedSequence instance used to initialize the generator if mode is “sequence” or is seed is a SeedSequence. None if mode is “legacy”.
PCG32provides 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
Generatoror 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-32 PRNG is represented by 2 64-bit unsigned integers.
PCG64for a similar implementation with a smaller period.
State and Seeding
PCG32state vector consists of 2 unsigned 64-bit values.
PCG32is seeded using a single 64-bit unsigned integer.
PCG32can be used in parallel applications using
advancewith a different value in each instance to produce non-overlapping sequences.
>>> from numpy.random import Generator >>> from randomgen import PCG32 >>> rg = [Generator(PCG32(1234, i + 1)) for i in range(10)] >>> for i in range(10): ... rg[i].bit_generator.advance(i * 2**32)
PCG32makes a guarantee that a fixed seed and will always produce the same random integer stream.
Seeding and State¶
Seed the generator
Get or set the PRNG state
Advance the underlying RNG as-if delta draws have occurred.
Jump the state a fixed increment
Returns a new bit generator with the state jumped
Return randoms as generated by the underlying BitGenerator