PRNG family

PCG

Permuted congruential generators: LCG state with a permutation on output

unverified 4 variants O'Neill, PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation

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–2014
  1. PCG published by Melissa E. O'Neill

How it works

  1. Advance the state: state = a*state + c mod 2^k (c = 0 for MCG).
  2. Apply the output permutation to the old or new state to produce the result.
  3. Select independent streams by choosing different odd increments c.
  4. 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

Scientific computing (NumPy default_rng)Simulations needing independent streamsGames and procedural content

Variants in NextSSL

4
AlgorithmTierSizes (bytes)StandardsAPI
PCG32
pcg32
unverified out 1–268435456 · seed 16 PCG32 (O'Neill 2014), NOT cryptographically secure root
PCG64
pcg64
unverified out 1–268435456 · seed 32 PCG64 (O'Neill 2014), NOT cryptographically secure root
PCG64-Dxsm
pcg64-dxsm
unverified out 1–268435456 · seed 32 PCG64 DXSM (O'Neill 2019), NOT cryptographically secure root
PCG64-MCG
pcg64-mcg
unverified out 1–268435456 · seed 16 PCG64 MCG (O'Neill 2014), NOT cryptographically secure root

Frequently asked questions

Which PCG variants does NextSSL include?

NextSSL registers 4 PCG variants: pcg32, pcg64, pcg64-dxsm, pcg64-mcg.