PCG32
Permuted congruential generators: LCG state with a permutation on output
Source found and wired, correctness not fully proven. Root API only. Reach it with NextSSL(root=True) in Python or the nextssl_root_* functions in C.
About PCG32
PCG32 is one of 4 PCG variants in the NextSSL registry, a non-cryptographic pseudorandom generator. It uses a 1–268,435,456-byte output and a 16-byte seed. Its registry entry cites PCG32 (O'Neill 2014), NOT cryptographically secure. It is also known as pcg-xsh-rr-64-32. NextSSL lists it in the unverified tier and exposes it through the root API only (NextSSL(root=True) in Python, nextssl_root_* in C).
Overview
PCG is a family of pseudorandom number generators that combine a linear congruential generator's state transition with an output permutation that hides its statistical weaknesses. They are fast, compact and statistically strong, and PCG64 is the default bit generator in NumPy, but they are not cryptographic.
A plain linear congruential generator (LCG) computes state = a*state + c modulo a power of two; its low bits have short periods and its output is easy to predict. PCG keeps the LCG state transition but outputs a permuted function of the state, such as a random rotation or an xorshift followed by a multiply, selected by the state's high bits. This produces output that passes demanding statistical test suites while keeping a tiny state.
Four variants are present. PCG32 uses a 64-bit state and produces 32-bit outputs. PCG64 uses a 128-bit LCG with the XSL-RR output function. PCG64-DXSM uses a stronger double-xorshift-multiply output function introduced later to address correlations between streams. PCG64-MCG uses a multiplicative congruential generator (c = 0), which is slightly faster but has a shorter period. Except for the MCG form, the variants support multiple independent streams selected by the increment.
History
2014–2014PCG published by Melissa E. O'Neill
How it works
- Advance the state: state = a*state + c mod 2^k (c = 0 for MCG).
- Apply the output permutation to the old or new state to produce the result.
- Select independent streams by choosing different odd increments c.
- Jump ahead in logarithmic time using LCG arithmetic.
Security notes
Not cryptographically secure: the internal state can be recovered from outputs with modest computation, making future outputs predictable. Do not use it for keys, nonces, session IDs or tokens; use the OS RNG or a DRBG.
Typical uses
Sizes
| Field | Bytes | Meaning |
|---|---|---|
| out | 1 – 268,435,456 | Output |
| seed | 16 | Seed |
Use it
from nextssl_demo import NextSSL
root = NextSSL(root=True) # tier 'unverified' is reachable from the root API only
buf = root.call("rng_fill", "pcg32", "seed=42", 32)[0] # not for keys
nextssl_root_rng_fill("pcg32", "seed=42", 32, out);
// prng is a root-only kind: use the C ABI (nextssl_root_*)
// or the Prng trait in nextssl-core/src/traits.rs
Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.
Other PCG variants
3More non-cryptographic prngs
All 26Frequently asked questions
What is PCG32?
PCG32 is a PRNG in the PCG family. PCG is a family of pseudorandom number generators that combine a linear congruential generator's state transition with an output permutation that hides its statistical weaknesses. It is also known as pcg-xsh-rr-64-32.
What are the PCG32 sizes?
In NextSSL, PCG32 uses: output 1 to 268,435,456 bytes.
Who designed PCG32 and when?
PCG32 belongs to the PCG family, first published in 2014 by Melissa E. O'Neill. Its origin: O'Neill, PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation.
Which standards define PCG32?
PCG32 is referenced by PCG32 (O'Neill 2014), NOT cryptographically secure.
Is PCG32 safe to use?
PCG32 is in the unverified tier. Source found and wired, correctness not fully proven. Root API only. It is only reachable through the root API (NextSSL(root=True) in Python, nextssl_root_* in C).
What other PCG variants are there?
NextSSL also registers pcg64, pcg64-dxsm, pcg64-mcg in the PCG family.
Related families
The classic long-period generator behind many language defaults, not for security
SplitMix64Counter-based 64-bit generator, widely used to seed other generators
xoshiro / xoroshiroFast linear generators from Blackman and Vigna for simulation, not for secrets
Operating system RNGThe kernel's cryptographically secure random number generator, the right default