aboutsummaryrefslogtreecommitdiff
path: root/rand/src/rngs/thread.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rand/src/rngs/thread.rs')
-rw-r--r--rand/src/rngs/thread.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/rand/src/rngs/thread.rs b/rand/src/rngs/thread.rs
index ff772e3..7977d85 100644
--- a/rand/src/rngs/thread.rs
+++ b/rand/src/rngs/thread.rs
@@ -87,10 +87,11 @@ thread_local!(
}
);
-/// Retrieve the lazily-initialized thread-local random number
-/// generator, seeded by the system. Intended to be used in method
-/// chaining style, e.g. `thread_rng().gen::<i32>()`, or cached locally, e.g.
-/// `let mut rng = thread_rng();`.
+/// Retrieve the lazily-initialized thread-local random number generator,
+/// seeded by the system. Intended to be used in method chaining style,
+/// e.g. `thread_rng().gen::<i32>()`, or cached locally, e.g.
+/// `let mut rng = thread_rng();`. Invoked by the `Default` trait, making
+/// `ThreadRng::default()` equivelent.
///
/// For more information see [`ThreadRng`].
///
@@ -99,6 +100,12 @@ pub fn thread_rng() -> ThreadRng {
ThreadRng { rng: THREAD_RNG_KEY.with(|t| t.get()) }
}
+impl Default for ThreadRng {
+ fn default() -> ThreadRng {
+ ::prelude::thread_rng()
+ }
+}
+
impl RngCore for ThreadRng {
#[inline(always)]
fn next_u32(&mut self) -> u32 {
@@ -125,7 +132,6 @@ impl CryptoRng for ThreadRng {}
#[cfg(test)]
mod test {
#[test]
- #[cfg(not(feature="stdweb"))]
fn test_thread_rng() {
use Rng;
let mut r = ::thread_rng();