diff options
| author | bors <bors@rust-lang.org> | 2015-01-16 03:02:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-16 03:02:54 +0000 |
| commit | b565501ad8b4e371e0aca0069c3f4781bd209254 (patch) | |
| tree | a669459825ecb6e8a78d4615fa2ccc0c2dee7836 /src/libstd | |
| parent | 8903c21d618fd25dca61d9bb668c5299d21feac9 (diff) | |
| parent | 42198c18f46aa1841ff2870c4841eafae7ec7e8d (diff) | |
| download | rust-b565501ad8b4e371e0aca0069c3f4781bd209254.tar.gz rust-b565501ad8b4e371e0aca0069c3f4781bd209254.zip | |
auto merge of #21213 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rand/mod.rs | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index a093e748d57..43ca7b13145 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -21,6 +21,8 @@ use prelude::v1::*; use collections::HashMap; use ffi::CString; use fmt; +// NOTE(stage0) remove import after a snapshot +#[cfg(stage0)] use hash::Hash; use io::pipe::{PipeStream, PipePair}; use io::{IoResult, IoError}; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 60d490982db..8130a6c82ec 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -374,9 +374,13 @@ impl Rng for ThreadRng { /// `random()` can generate various types of random things, and so may require /// type hinting to generate the specific type you want. /// +/// This function uses the thread local random number generator. This means +/// that if you're calling `random()` in a loop, caching the generator can +/// increase performance. An example is shown below. +/// /// # Examples /// -/// ```rust +/// ``` /// use std::rand; /// /// let x = rand::random(); @@ -389,6 +393,27 @@ impl Rng for ThreadRng { /// println!("Better lucky than good!"); /// } /// ``` +/// +/// Caching the thread local random number generator: +/// +/// ``` +/// use std::rand; +/// use std::rand::Rng; +/// +/// let mut v = vec![1, 2, 3]; +/// +/// for x in v.iter_mut() { +/// *x = rand::random() +/// } +/// +/// // would be faster as +/// +/// let mut rng = rand::thread_rng(); +/// +/// for x in v.iter_mut() { +/// *x = rng.gen(); +/// } +/// ``` #[inline] pub fn random<T: Rand>() -> T { thread_rng().gen() |
