@@ -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,8 +736,8 @@ 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 `u8` arrays (expressed with the
740
+ /// `Sized + AsMut<[u8]>` bound) .
741
741
///
742
742
/// It is recommended to seed PRNG's with a seed of more than circa
743
743
/// 100 bits, which means an array of `[u8; 12]` or greater to avoid picking
@@ -764,19 +764,19 @@ 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.
773
+ /// Many non-cryptographic PRNGs will show statistical bias in their first
774
+ /// results if their seed numbers are small or if there is a simple pattern
775
+ /// between them.
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`.
778
+ /// Also cryptographically secure PRNG's (like `thread_rng`) can be used
779
+ /// without hesitation.
780
780
///
781
781
/// Seeding a small PRNG from another small PRNG is be possible, but
782
782
/// something to be careful with. An extreme example of how this can go
@@ -786,6 +786,8 @@ pub trait SeedableRng: Sized {
786
786
/// PRNG implementations are allowed to assume that a good RNG is provided
787
787
/// for seeding, and that it is cryptographically secure when appropriate.
788
788
/// There are no reproducibility requirements like endianness conversion.
789
+ ///
790
+ /// [`NewRng`]: trait.NewRng.html
789
791
fn from_rng < R : Rng > ( mut rng : R ) -> Result < Self , Error > {
790
792
let mut seed = Self :: Seed :: default ( ) ;
791
793
rng. try_fill_bytes ( seed. as_mut ( ) ) ?;
@@ -794,13 +796,14 @@ pub trait SeedableRng: Sized {
794
796
}
795
797
796
798
797
- /// Seeding mechanism for PRNGs, providing a `new` function.
798
- /// This is the recommended way to create (pseudo) random number generators,
799
- /// unless a deterministic seed is desired (in which case
800
- /// `SeedableRng::from_seed` should be used).
799
+ /// A convenient way to seed new algorithmic generators, otherwise known as
800
+ /// pseudo-random number generators (PRNGs).
801
+ ///
802
+ /// This is the recommended way to create PRNG's, unless a deterministic seed is
803
+ /// desired (in which case `SeedableRng::from_seed` should be used).
801
804
///
802
805
/// Note: this trait is automatically implemented for any PRNG implementing
803
- /// `SeedableRng` and is not intended to be implemented by users.
806
+ /// [ `SeedableRng`] and is not intended to be implemented by users.
804
807
///
805
808
/// ## Example
806
809
///
@@ -810,6 +813,8 @@ pub trait SeedableRng: Sized {
810
813
/// let mut rng = StdRng::new().unwrap();
811
814
/// println!("Random die roll: {}", rng.gen_range(1, 7));
812
815
/// ```
816
+ ///
817
+ /// [`SeedableRng`]: trait.SeedableRng.html
813
818
#[ cfg( feature="std" ) ]
814
819
pub trait NewRng : SeedableRng {
815
820
/// Creates a new instance, automatically seeded with fresh entropy.
0 commit comments