Skip to content

Commit f292643

Browse files
committed
Use OsRng for thread_rng.
1 parent fbb7e31 commit f292643

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

src/lib.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -855,19 +855,7 @@ pub fn weak_rng() -> XorShiftRng {
855855
}
856856
}
857857

858-
/// Controls how the thread-local RNG is reseeded.
859-
struct ThreadRngReseeder;
860-
861-
impl reseeding::Reseeder<StdRng> for ThreadRngReseeder {
862-
fn reseed(&mut self, rng: &mut StdRng) {
863-
*rng = match StdRng::new() {
864-
Ok(r) => r,
865-
Err(e) => panic!("could not reseed thread_rng: {}", e)
866-
}
867-
}
868-
}
869-
const THREAD_RNG_RESEED_THRESHOLD: u64 = 32_768;
870-
type ThreadRngInner = reseeding::ReseedingRng<StdRng, ThreadRngReseeder>;
858+
type ThreadRngInner = os::OsRng;
871859

872860
/// The thread-local RNG.
873861
#[derive(Clone)]
@@ -881,21 +869,13 @@ pub struct ThreadRng {
881869
///
882870
/// The RNG provided will reseed itself from the operating system
883871
/// after generating a certain amount of randomness.
884-
///
885-
/// The internal RNG used is platform and architecture dependent, even
886-
/// if the operating system random number generator is rigged to give
887-
/// the same sequence always. If absolute consistency is required,
888-
/// explicitly select an RNG, e.g. `IsaacRng` or `Isaac64Rng`.
889872
pub fn thread_rng() -> ThreadRng {
890873
// used to make space in TLS for a random number generator
891874
thread_local!(static THREAD_RNG_KEY: Rc<RefCell<ThreadRngInner>> = {
892-
let r = match StdRng::new() {
875+
let rng = match os::OsRng::new() {
893876
Ok(r) => r,
894877
Err(e) => panic!("could not initialize thread_rng: {}", e)
895878
};
896-
let rng = reseeding::ReseedingRng::new(r,
897-
THREAD_RNG_RESEED_THRESHOLD,
898-
ThreadRngReseeder);
899879
Rc::new(RefCell::new(rng))
900880
});
901881

0 commit comments

Comments
 (0)