Skip to content

Commit faa78de

Browse files
committed
Documentation improvements
1 parent 2f42698 commit faa78de

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/lib.rs

+24-19
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ use prng::Isaac64Rng as IsaacWordRng;
276276

277277
use distributions::{Range, IndependentSample};
278278
use distributions::range::SampleRange;
279-
#[cfg(feature="std")]use reseeding::{ReseedingRng, ReseedWithNew};
279+
#[cfg(feature="std")] use reseeding::{ReseedingRng, ReseedWithNew};
280280

281281
// public modules
282282
pub mod distributions;
@@ -736,8 +736,8 @@ impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> {
736736
///
737737
/// Each pseudo-random number generator (PRNG) should implement this.
738738
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).
741741
///
742742
/// It is recommended to seed PRNG's with a seed of more than circa
743743
/// 100 bits, which means an array of `[u8; 12]` or greater to avoid picking
@@ -764,19 +764,19 @@ pub trait SeedableRng: Sized {
764764

765765
/// Create a new PRNG seeded from another `Rng`.
766766
///
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`.
770769
///
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.
776776
///
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.
780780
///
781781
/// Seeding a small PRNG from another small PRNG is be possible, but
782782
/// something to be careful with. An extreme example of how this can go
@@ -786,6 +786,8 @@ pub trait SeedableRng: Sized {
786786
/// PRNG implementations are allowed to assume that a good RNG is provided
787787
/// for seeding, and that it is cryptographically secure when appropriate.
788788
/// There are no reproducibility requirements like endianness conversion.
789+
///
790+
/// [`NewRng`]: trait.NewRng.html
789791
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
790792
let mut seed = Self::Seed::default();
791793
rng.try_fill_bytes(seed.as_mut())?;
@@ -794,13 +796,14 @@ pub trait SeedableRng: Sized {
794796
}
795797

796798

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).
801804
///
802805
/// 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.
804807
///
805808
/// ## Example
806809
///
@@ -810,6 +813,8 @@ pub trait SeedableRng: Sized {
810813
/// let mut rng = StdRng::new().unwrap();
811814
/// println!("Random die roll: {}", rng.gen_range(1, 7));
812815
/// ```
816+
///
817+
/// [`SeedableRng`]: trait.SeedableRng.html
813818
#[cfg(feature="std")]
814819
pub trait NewRng: SeedableRng {
815820
/// Creates a new instance, automatically seeded with fresh entropy.

0 commit comments

Comments
 (0)