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, int, array_like[int], SeedSequence}, optional
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, int}, optional
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.
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 aGenerator
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.References
[1]“PCG, A Family of Better Random Number Generators”, https://www.pcg-random.org/
[2]O’Neill, Melissa E. “PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation”
[3]NumPy GitHub Repository. 2020. The PCG Implementation Provided By Numpy Has Significant, Dangerous Self-Correlation. [online] Available at: <https://github.com/numpy/numpy/issues/16313> [Accessed 16 June 2020].
Examples
Parallel Features
PCG64DXSM
can be used in parallel applications by callingadvance
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)
- Attributes:
- lockthreading.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.
- seed_seq{None, SeedSequence}
The SeedSequence instance used to initialize the generator if mode is “sequence” or is seed is a SeedSequence. None if mode is “legacy”.
Seeding and State¶
| Seed the generator |
Get or set the PRNG state |
Parallel generation¶
| Advance the underlying RNG as-if delta draws have occurred. |
| Not implemented. |
| Returns a new bit generator with the state jumped |
Extending¶
CFFI interface | |
ctypes interface |
Testing¶
| Return randoms as generated by the underlying BitGenerator |