99//! A small fast RNG
1010
1111use { 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 ;
1317
1418/// An RNG recommended when small state, cheap initialization and good
1519/// performance are required. The PRNG algorithm in `SmallRng` is chosen to be
@@ -20,9 +24,12 @@ use ::rand_xorshift::XorShiftRng;
2024/// future library versions may use a different internal generator with
2125/// different output. Further, this generator may not be portable and can
2226/// 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).
2430///
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.
2633///
2734/// # Examples
2835///
@@ -61,10 +68,10 @@ use ::rand_xorshift::XorShiftRng;
6168/// [`FromEntropy`]: ../trait.FromEntropy.html
6269/// [`StdRng`]: struct.StdRng.html
6370/// [`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
6673#[ derive( Clone , Debug ) ]
67- pub struct SmallRng ( XorShiftRng ) ;
74+ pub struct SmallRng ( Rng ) ;
6875
6976impl RngCore for SmallRng {
7077 #[ inline( always) ]
@@ -87,13 +94,13 @@ impl RngCore for SmallRng {
8794}
8895
8996impl SeedableRng for SmallRng {
90- type Seed = <XorShiftRng as SeedableRng >:: Seed ;
97+ type Seed = <Rng as SeedableRng >:: Seed ;
9198
9299 fn from_seed ( seed : Self :: Seed ) -> Self {
93- SmallRng ( XorShiftRng :: from_seed ( seed) )
100+ SmallRng ( Rng :: from_seed ( seed) )
94101 }
95102
96103 fn from_rng < R : RngCore > ( rng : R ) -> Result < Self , Error > {
97- XorShiftRng :: from_rng ( rng) . map ( SmallRng )
104+ Rng :: from_rng ( rng) . map ( SmallRng )
98105 }
99106}
0 commit comments