Skip to content

Commit 1302d4e

Browse files
committed
Update documentation
1 parent 2f42698 commit 1302d4e

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

src/lib.rs

Lines changed: 28 additions & 21 deletions
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,12 +736,12 @@ 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 types mutably-dereferencable as `u8`
740+
/// arrays (we recommend `[u8; N]` for some `N`).
741741
///
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
743743
/// 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.
745745
///
746746
/// For cryptographic RNG's a seed of 256 bits is recommended, `[u8; 32]`.
747747
type Seed: Sized + Default + AsMut<[u8]>;
@@ -764,28 +764,33 @@ 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. 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.
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`] or
778+
/// from a cryptographic PRNG; if creating a new generator for cryptography
779+
/// you *must* do this.
780780
///
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
782782
/// 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.
785786
///
786787
/// PRNG implementations are allowed to assume that a good RNG is provided
787788
/// for seeding, and that it is cryptographically secure when appropriate.
788789
/// 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
789794
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
790795
let mut seed = Self::Seed::default();
791796
rng.try_fill_bytes(seed.as_mut())?;
@@ -794,8 +799,10 @@ pub trait SeedableRng: Sized {
794799
}
795800

796801

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,
799806
/// unless a deterministic seed is desired (in which case
800807
/// `SeedableRng::from_seed` should be used).
801808
///

0 commit comments

Comments
 (0)