Expand description
The PCG random number generators.
This is a native Rust implementation of a small selection of PCG generators. The primary goal of this crate is simple, minimal, well-tested code; in other words it is explicitly not a goal to re-implement all of PCG.
This crate provides:
Pcg32
akaLcg64Xsh32
, officially known aspcg32
, a general purpose RNG. This is a good choice on both 32-bit and 64-bit CPUs (for 32-bit output).Pcg64
akaLcg128Xsl64
, officially known aspcg64
, a general purpose RNG. This is a good choice on 64-bit CPUs.Pcg64Mcg
akaMcg128Xsl64
, officially known aspcg64_fast
, a general purpose RNG using 128-bit multiplications. This has poor performance on 32-bit CPUs but is a good choice on 64-bit CPUs for both 32-bit and 64-bit output.
Both of these use 16 bytes of state and 128-bit seeds, and are considered value-stable (i.e. any change affecting the output given a fixed seed would be considered a breaking change to the crate).
§Example
To initialize a generator, use the SeedableRng
trait:
use rand_core::{SeedableRng, RngCore};
use rand_pcg::Pcg64Mcg;
let mut rng = Pcg64Mcg::seed_from_u64(0);
let x: u32 = rng.next_u32();
The functionality of this crate is implemented using traits from the rand_core
crate, but you may use the rand
crate for further functionality to initialize the generator from various sources and to generate random values:
ⓘ
use rand::{Rng, SeedableRng};
use rand_pcg::Pcg64Mcg;
let mut rng = Pcg64Mcg::from_entropy();
let x: f64 = rng.gen();
Structs§
- A PCG random number generator (XSH RR 64/32 (LCG) variant).
- A PCG random number generator (CM DXSM 128/64 (LCG) variant).
- A PCG random number generator (XSL RR 128/64 (LCG) variant).
- A PCG random number generator (XSL 128/64 (MCG) variant).
Type Aliases§
Lcg64Xsh32
is also officially known aspcg32
.Lcg128Xsl64
is also officially known aspcg64
.Lcg128CmDxsm64
is also known asPCG64DXSM
.- A friendly name for
Mcg128Xsl64
(also known aspcg64_fast
).