Skip to content

Commit 2b5eac5

Browse files
authored
Merge pull request #657 from burdges/def_thread_rng
Add Default for ThreadRng
2 parents 033c253 + 57c54bb commit 2b5eac5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/rngs/thread.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ thread_local!(
8787
}
8888
);
8989

90-
/// Retrieve the lazily-initialized thread-local random number
91-
/// generator, seeded by the system. Intended to be used in method
92-
/// chaining style, e.g. `thread_rng().gen::<i32>()`, or cached locally, e.g.
93-
/// `let mut rng = thread_rng();`.
90+
/// Retrieve the lazily-initialized thread-local random number generator,
91+
/// seeded by the system. Intended to be used in method chaining style,
92+
/// e.g. `thread_rng().gen::<i32>()`, or cached locally, e.g.
93+
/// `let mut rng = thread_rng();`. Invoked by the `Default` trait, making
94+
/// `ThreadRng::default()` equivelent.
9495
///
9596
/// For more information see [`ThreadRng`].
9697
///
@@ -99,6 +100,12 @@ pub fn thread_rng() -> ThreadRng {
99100
ThreadRng { rng: THREAD_RNG_KEY.with(|t| t.get()) }
100101
}
101102

103+
impl Default for ThreadRng {
104+
fn default() -> ThreadRng {
105+
::prelude::thread_rng()
106+
}
107+
}
108+
102109
impl RngCore for ThreadRng {
103110
#[inline(always)]
104111
fn next_u32(&mut self) -> u32 {

0 commit comments

Comments
 (0)