Skip to content

Commit c873c21

Browse files
committed
Document rand module with more emphasis on cryptographic security
1 parent 7208095 commit c873c21

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/libstd/rand.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ impl<R: Rng> RngUtil for R {
610610
}
611611

612612
/// Create a random number generator with a default algorithm and seed.
613+
///
614+
/// It returns the cryptographically-safest `Rng` algorithm currently
615+
/// available in Rust. If you require a specifically seeded `Rng` for
616+
/// consistency over time you should pick one algorithm and create the
617+
/// `Rng` yourself.
613618
pub fn rng() -> IsaacRng {
614619
IsaacRng::new()
615620
}
@@ -619,6 +624,8 @@ static RAND_SIZE: u32 = 1 << RAND_SIZE_LEN;
619624

620625
/// A random number generator that uses the [ISAAC
621626
/// algorithm](http://en.wikipedia.org/wiki/ISAAC_%28cipher%29).
627+
///
628+
/// The ISAAC algorithm is suitable for cryptographic purposes.
622629
pub struct IsaacRng {
623630
priv cnt: u32,
624631
priv rsl: [u32, .. RAND_SIZE],
@@ -794,8 +801,11 @@ impl Rng for IsaacRng {
794801
}
795802

796803
/// An [Xorshift random number
797-
/// generator](http://en.wikipedia.org/wiki/Xorshift). Not suitable for
798-
/// cryptographic purposes.
804+
/// generator](http://en.wikipedia.org/wiki/Xorshift).
805+
///
806+
/// The Xorshift algorithm is not suitable for cryptographic purposes
807+
/// but is very fast. If you do not know for sure that it fits your
808+
/// requirements, use a more secure one such as `IsaacRng`.
799809
pub struct XorShiftRng {
800810
priv x: u32,
801811
priv y: u32,

0 commit comments

Comments
 (0)