@@ -276,7 +276,7 @@ use prng::Isaac64Rng as IsaacWordRng;
276
276
277
277
use distributions:: { Range , IndependentSample } ;
278
278
use distributions:: range:: SampleRange ;
279
- #[ cfg( feature="std" ) ] use reseeding:: { ReseedingRng , ReseedWithNew } ;
279
+ #[ cfg( feature="std" ) ] use reseeding:: { ReseedingRng , ReseedWithNew } ;
280
280
281
281
// public modules
282
282
pub mod distributions;
@@ -736,12 +736,12 @@ impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> {
736
736
///
737
737
/// Each pseudo-random number generator (PRNG) should implement this.
738
738
pub trait SeedableRng : Sized {
739
- /// Seed type, which is restricted to `u8` arrays with a length of
740
- /// 4, 8, 12, 16, 24 and 32 .
739
+ /// Seed type, which is restricted to types mutably-dereferencable as `u8`
740
+ /// arrays (we recommend `[u8; N]` for some `N`) .
741
741
///
742
- /// It is recommended to seed PRNG's with a seed of more than circa
742
+ /// It is recommended to seed PRNGs with a seed of at least circa
743
743
/// 100 bits, which means an array of `[u8; 12]` or greater to avoid picking
744
- /// RNG's with partially overlapping periods.
744
+ /// RNGs with partially overlapping periods.
745
745
///
746
746
/// For cryptographic RNG's a seed of 256 bits is recommended, `[u8; 32]`.
747
747
type Seed : Sized + Default + AsMut < [ u8 ] > ;
@@ -764,28 +764,33 @@ pub trait SeedableRng: Sized {
764
764
765
765
/// Create a new PRNG seeded from another `Rng`.
766
766
///
767
- /// This is the recommended way to initialize PRNGs. See the `NewRng`
768
- /// trait that provides a convenient `new` method using `from_rng` and a
769
- /// good entropy source.
767
+ /// This is the recommended way to initialize PRNGs. The [`NewRng`] trait
768
+ /// provides a convenient new method based on from_rng.
770
769
///
771
- /// It is recommended to use a good source of randomness to initialize the
772
- /// PRNG. Otherwise small PRNG's could show statistical bias in the first
773
- /// couple of results, and possibly not use their entire period well.
774
- /// Cryptographic PRNG's can be less secure or even insecure when they are
775
- /// seeded from a non-cryptographic PRNG.
770
+ /// It is important to use a good source of randomness to initialize the
771
+ /// PRNG. Cryptographic PRNG may be rendered insecure when seeded from a
772
+ /// non-cryptographic PRNG or with insufficient entropy. Some
773
+ /// non-cryptographic PRNGs may show statistical bias in their first
774
+ /// results and may even have abnormally short periods if their seed
775
+ /// numbers are not well distributed.
776
776
///
777
- /// Examples of good RNG's for seeding are entropy sources like `OsRng` and
778
- /// `JitterRng`. Also cryptographically secure PRNG's (like `thread_rng`)
779
- /// can be used without hesitation .
777
+ /// Prefer to seed from a strong external entropy source like [ `OsRng`] or
778
+ /// from a cryptographic PRNG; if creating a new generator for cryptography
779
+ /// you *must* do this .
780
780
///
781
- /// Seeding a small PRNG from another small PRNG is be possible, but
781
+ /// Seeding a small PRNG from another small PRNG is possible, but
782
782
/// something to be careful with. An extreme example of how this can go
783
- /// wrong is seeding an Xorshift RNG from another Xorshift RNG. That will
784
- /// effectively clone the generator.
783
+ /// wrong is seeding an [`XorShiftRng`] from another [`XorShiftRng`], which
784
+ /// will effectively clone the generator. In general seeding from a
785
+ /// generator which is hard to predict is probably okay.
785
786
///
786
787
/// PRNG implementations are allowed to assume that a good RNG is provided
787
788
/// for seeding, and that it is cryptographically secure when appropriate.
788
789
/// There are no reproducibility requirements like endianness conversion.
790
+ ///
791
+ /// [`NewRng`]: trait.NewRng.html
792
+ /// [`OsRng`]: os/struct.OsRng.html
793
+ /// [`XorShiftRng`]: prng/xorshift/struct.XorShiftRng.html
789
794
fn from_rng < R : Rng > ( mut rng : R ) -> Result < Self , Error > {
790
795
let mut seed = Self :: Seed :: default ( ) ;
791
796
rng. try_fill_bytes ( seed. as_mut ( ) ) ?;
@@ -794,8 +799,10 @@ pub trait SeedableRng: Sized {
794
799
}
795
800
796
801
797
- /// Seeding mechanism for PRNGs, providing a `new` function.
798
- /// This is the recommended way to create (pseudo) random number generators,
802
+ /// A convenient way to seed new algorithmic generators, otherwise known as
803
+ /// pseudo-random number generators (PRNGs).
804
+ ///
805
+ /// This is the recommended way to create PRNGs,
799
806
/// unless a deterministic seed is desired (in which case
800
807
/// `SeedableRng::from_seed` should be used).
801
808
///
0 commit comments