Skip to content

Commit 26c2491

Browse files
committed
Add PCG to benchmarks and PRNG module documentation
1 parent 83ab2d7 commit 26c2491

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

benches/generators.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern crate rand;
1313
extern crate rand_isaac;
1414
extern crate rand_chacha;
1515
extern crate rand_hc128;
16+
extern crate rand_pcg;
1617
extern crate rand_xorshift;
1718

1819
const RAND_BENCH_N: u64 = 1000;
@@ -27,6 +28,7 @@ use rand::rngs::{OsRng, JitterRng, EntropyRng};
2728
use rand_isaac::{IsaacRng, Isaac64Rng};
2829
use rand_chacha::ChaChaRng;
2930
use rand_hc128::{Hc128Rng, Hc128Core};
31+
use rand_pcg::{Lcg64Xsh32, Mcg128Xsl64};
3032
use rand_xorshift::XorShiftRng;
3133

3234
macro_rules! gen_bytes {
@@ -47,6 +49,8 @@ macro_rules! gen_bytes {
4749
}
4850

4951
gen_bytes!(gen_bytes_xorshift, XorShiftRng::from_entropy());
52+
gen_bytes!(gen_bytes_lcg64_xsh32, Lcg64Xsh32::from_entropy());
53+
gen_bytes!(gen_bytes_mcg128_xsh64, Mcg128Xsl64::from_entropy());
5054
gen_bytes!(gen_bytes_chacha20, ChaChaRng::from_entropy());
5155
gen_bytes!(gen_bytes_hc128, Hc128Rng::from_entropy());
5256
gen_bytes!(gen_bytes_isaac, IsaacRng::from_entropy());
@@ -73,6 +77,8 @@ macro_rules! gen_uint {
7377
}
7478

7579
gen_uint!(gen_u32_xorshift, u32, XorShiftRng::from_entropy());
80+
gen_uint!(gen_u32_lcg64_xsh32, u32, Lcg64Xsh32::from_entropy());
81+
gen_uint!(gen_u32_mcg128_xsh64, u32, Mcg128Xsl64::from_entropy());
7682
gen_uint!(gen_u32_chacha20, u32, ChaChaRng::from_entropy());
7783
gen_uint!(gen_u32_hc128, u32, Hc128Rng::from_entropy());
7884
gen_uint!(gen_u32_isaac, u32, IsaacRng::from_entropy());
@@ -82,6 +88,8 @@ gen_uint!(gen_u32_small, u32, SmallRng::from_entropy());
8288
gen_uint!(gen_u32_os, u32, OsRng::new().unwrap());
8389

8490
gen_uint!(gen_u64_xorshift, u64, XorShiftRng::from_entropy());
91+
gen_uint!(gen_u64_lcg64_xsh32, u64, Lcg64Xsh32::from_entropy());
92+
gen_uint!(gen_u64_mcg128_xsh64, u64, Mcg128Xsl64::from_entropy());
8593
gen_uint!(gen_u64_chacha20, u64, ChaChaRng::from_entropy());
8694
gen_uint!(gen_u64_hc128, u64, Hc128Rng::from_entropy());
8795
gen_uint!(gen_u64_isaac, u64, IsaacRng::from_entropy());
@@ -115,6 +123,8 @@ macro_rules! init_gen {
115123
}
116124

117125
init_gen!(init_xorshift, XorShiftRng);
126+
init_gen!(init_lcg64_xsh32, Lcg64Xsh32);
127+
init_gen!(init_mcg128_xsh64, Mcg128Xsl64);
118128
init_gen!(init_hc128, Hc128Rng);
119129
init_gen!(init_isaac, IsaacRng);
120130
init_gen!(init_isaac64, Isaac64Rng);

src/prng/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@
4545
//!
4646
//! | name | full name | performance | memory | quality | period | features |
4747
//! |------|-----------|-------------|--------|---------|--------|----------|
48-
//! | [`XorShiftRng`] | Xorshift 32/128 | ★★★☆☆ | 16 bytes | ★☆☆☆☆ | `u32` * 2<sup>128</sup> - 1 | — |
48+
//! | [`Pcg32`] | PCG XSH RR 64/32 (LCG) | ★★★☆☆ | 16 bytes | ★★★☆☆ | `u32` * 2<sup>64</sup> | — |
49+
//! | [`Pcg64Mcg`] | PCG XSL 128/64 (MCG) | ★★★★☆ | 16 bytes | ★★★☆☆ | `u64` * 2<sup>126</sup> | — |
50+
//! | [`XorShiftRng`] | Xorshift 32/128 | ★★★★☆ | 16 bytes | ★☆☆☆☆ | `u32` * 2<sup>128</sup> - 1 | — |
4951
//!
5052
// Quality stars [not rendered in documentation]:
51-
// 5. reserved for crypto-level (e.g. ChaCha8, ISAAC)
52-
// 4. good performance on TestU01 and PractRand, good theory
53+
// 5. proven cryptographic quality (e.g. ChaCha20)
54+
// 4. potentially cryptographic, but low margin or lack of theory (e.g. ChaCha8, ISAAC)
55+
// 3. good performance on TestU01 and PractRand, good theory
5356
// (e.g. PCG, truncated Xorshift*)
54-
// 3. good performance on TestU01 and PractRand, but "falling through the
55-
// cracks" or insufficient theory (e.g. SFC, Xoshiro)
56-
// 2. imperfect performance on tests or other limiting properties, but not
57-
// terrible (e.g. Xoroshiro128+)
57+
// 2. imperfect performance on tests or other limiting properties, or
58+
// insufficient theory, but not terrible (e.g. SFC, Xoshiro, Xoroshiro128+)
5859
// 1. clear deficiencies in test results, cycle length, theory, or other
5960
// properties (e.g. Xorshift)
6061
//
@@ -297,6 +298,8 @@
297298
//! [`rngs` module]: ../rngs/index.html
298299
//! [basic PRNGs]: #basic-pseudo-random-number-generators-prngs
299300
//! [CSPRNGs]: #cryptographically-secure-pseudo-random-number-generators-csprngs
301+
//! [`Pcg32`]: ../../rand_pcg/type.Pcg32.html
302+
//! [`Pcg64Mcg`]: ../../rand_pcg/type.Pcg64Mcg.html
300303
//! [`XorShiftRng`]: ../../rand_xorshift/struct.XorShiftRng.html
301304
//! [`ChaChaRng`]: ../../rand_chacha/struct.ChaChaRng.html
302305
//! [`Hc128Rng`]: ../../rand_hc128/struct.Hc128Rng.html

src/rngs/small.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ type Rng = ::rand_pcg::Pcg32;
2525
/// different output. Further, this generator may not be portable and can
2626
/// produce different output depending on the architecture. If you require
2727
/// reproducible output, use a named RNG. Refer to the documentation on the
28-
/// [`prng` module](../../prng.index.html) or the
29-
/// [small-rngs repo](https://github.com/rust-random/small-rngs).
28+
/// [`prng` module](../prng/index.html).
3029
///
3130
/// The current algorithm is [`Pcg64Mcg`] on 64-bit platforms with Rust version
3231
/// 1.26 and later, or [`Pcg32`] otherwise.

0 commit comments

Comments
 (0)