9
9
//! A small fast RNG
10
10
11
11
use { RngCore , SeedableRng , Error } ;
12
- use :: rand_xorshift:: XorShiftRng ;
12
+
13
+ #[ cfg( all( rust_1_26, target_pointer_width = "64" ) ) ]
14
+ type Rng = :: rand_pcg:: Pcg64Mcg ;
15
+ #[ cfg( not( all( rust_1_26, target_pointer_width = "64" ) ) ) ]
16
+ type Rng = :: rand_pcg:: Pcg32 ;
13
17
14
18
/// An RNG recommended when small state, cheap initialization and good
15
19
/// performance are required. The PRNG algorithm in `SmallRng` is chosen to be
@@ -20,9 +24,12 @@ use ::rand_xorshift::XorShiftRng;
20
24
/// future library versions may use a different internal generator with
21
25
/// different output. Further, this generator may not be portable and can
22
26
/// produce different output depending on the architecture. If you require
23
- /// reproducible output, use a named RNG, for example [`XorShiftRng`].
27
+ /// 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).
24
30
///
25
- /// The current algorithm used on all platforms is [Xorshift].
31
+ /// The current algorithm is [`Pcg64Mcg`] on 64-bit platforms with Rust version
32
+ /// 1.26 and later, or [`Pcg32`] otherwise.
26
33
///
27
34
/// # Examples
28
35
///
@@ -61,10 +68,10 @@ use ::rand_xorshift::XorShiftRng;
61
68
/// [`FromEntropy`]: ../trait.FromEntropy.html
62
69
/// [`StdRng`]: struct.StdRng.html
63
70
/// [`thread_rng`]: ../fn.thread_rng.html
64
- /// [Xorshift ]: ../../rand_xorshift/struct.XorShiftRng .html
65
- /// [`XorShiftRng `]: ../../rand_xorshift/struct.XorShiftRng .html
71
+ /// [`Pcg64Mcg` ]: https://docs.rs/rand_pcg/0.1.0/rand_pcg/type.Pcg64Mcg .html
72
+ /// [`Pcg32 `]: https://docs.rs/rand_pcg/0.1.0/rand_pcg/type.Pcg32 .html
66
73
#[ derive( Clone , Debug ) ]
67
- pub struct SmallRng ( XorShiftRng ) ;
74
+ pub struct SmallRng ( Rng ) ;
68
75
69
76
impl RngCore for SmallRng {
70
77
#[ inline( always) ]
@@ -87,13 +94,13 @@ impl RngCore for SmallRng {
87
94
}
88
95
89
96
impl SeedableRng for SmallRng {
90
- type Seed = <XorShiftRng as SeedableRng >:: Seed ;
97
+ type Seed = <Rng as SeedableRng >:: Seed ;
91
98
92
99
fn from_seed ( seed : Self :: Seed ) -> Self {
93
- SmallRng ( XorShiftRng :: from_seed ( seed) )
100
+ SmallRng ( Rng :: from_seed ( seed) )
94
101
}
95
102
96
103
fn from_rng < R : RngCore > ( rng : R ) -> Result < Self , Error > {
97
- XorShiftRng :: from_rng ( rng) . map ( SmallRng )
104
+ Rng :: from_rng ( rng) . map ( SmallRng )
98
105
}
99
106
}
0 commit comments