Skip to content

Commit 1ee0a32

Browse files
committed
Use OsRng for thread_rng.
1 parent 200b0fc commit 1ee0a32

File tree

1 file changed

+2
-23
lines changed

1 file changed

+2
-23
lines changed

src/lib.rs

+2-23
Original file line numberDiff line numberDiff line change
@@ -862,20 +862,7 @@ pub fn weak_rng() -> XorShiftRng {
862862
}
863863
}
864864

865-
/// Controls how the thread-local RNG is reseeded.
866-
#[derive(Debug)]
867-
struct ThreadRngReseeder;
868-
869-
impl reseeding::Reseeder<StdRng> for ThreadRngReseeder {
870-
fn reseed(&mut self, rng: &mut StdRng) {
871-
*rng = match StdRng::new() {
872-
Ok(r) => r,
873-
Err(e) => panic!("could not reseed thread_rng: {}", e)
874-
}
875-
}
876-
}
877-
const THREAD_RNG_RESEED_THRESHOLD: u64 = 32_768;
878-
type ThreadRngInner = reseeding::ReseedingRng<StdRng, ThreadRngReseeder>;
865+
type ThreadRngInner = os::OsRng;
879866

880867
/// The thread-local RNG.
881868
#[derive(Clone, Debug)]
@@ -889,21 +876,13 @@ pub struct ThreadRng {
889876
///
890877
/// The RNG provided will reseed itself from the operating system
891878
/// after generating a certain amount of randomness.
892-
///
893-
/// The internal RNG used is platform and architecture dependent, even
894-
/// if the operating system random number generator is rigged to give
895-
/// the same sequence always. If absolute consistency is required,
896-
/// explicitly select an RNG, e.g. `IsaacRng` or `Isaac64Rng`.
897879
pub fn thread_rng() -> ThreadRng {
898880
// used to make space in TLS for a random number generator
899881
thread_local!(static THREAD_RNG_KEY: Rc<RefCell<ThreadRngInner>> = {
900-
let r = match StdRng::new() {
882+
let rng = match os::OsRng::new() {
901883
Ok(r) => r,
902884
Err(e) => panic!("could not initialize thread_rng: {}", e)
903885
};
904-
let rng = reseeding::ReseedingRng::new(r,
905-
THREAD_RNG_RESEED_THRESHOLD,
906-
ThreadRngReseeder);
907886
Rc::new(RefCell::new(rng))
908887
});
909888

0 commit comments

Comments
 (0)