Skip to main content

Module rand_pcg

Module rand_pcg 

Source
Expand description

PCG family of fast, non-cryptographic random number generators.


rand_pcg provides random number generators based on the PCG family of algorithms. These are fast, have good statistical quality, and are portable — given the same seed they produce identical output on all platforms.

They are not cryptographically secure. Use rand_chacha when security matters.

The main types are:

  • Pcg32 – 32-bit output, 64-bit state. Good general-purpose default.
  • Pcg64 – 64-bit output, 128-bit state. Better for generating 64-bit values.

§Example

use rand::SeedableRng;
use rand::Rng;
use rand_pcg::Pcg32;

let mut rng = Pcg32::seed_from_u64(42);

let value: u32 = rng.random();
let in_range: f64 = rng.random_range(0.0..1.0);
let coin: bool = rng.random();

Modules§

rand_core
Random number generation traits

Structs§

Lcg64Xsh32
A PCG random number generator (XSH RR 64/32 (LCG) variant).
Lcg128CmDxsm64
A PCG random number generator (CM DXSM 128/64 (LCG) variant).
Lcg128Xsl64
A PCG random number generator (XSL RR 128/64 (LCG) variant).
Mcg128Xsl64
A PCG random number generator (XSL 128/64 (MCG) variant).

Type Aliases§

Pcg32
Lcg64Xsh32 is also officially known as pcg32.
Pcg64
Lcg128Xsl64 is also officially known as pcg64.
Pcg64Dxsm
Lcg128CmDxsm64 is also known as PCG64DXSM.
Pcg64Mcg
A friendly name for Mcg128Xsl64 (also known as pcg64_fast).