Skip to content

Commit a68ec1d

Browse files
committed
Test reseeding on clone
1 parent 47a5724 commit a68ec1d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/reseeding.rs

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use rand_core::impls::BlockRng;
1919
/// A wrapper around any PRNG which reseeds the underlying PRNG after it has
2020
/// generated a certain number of random bytes.
2121
///
22+
/// When the RNG gets cloned, the clone is reseeded on first use.
23+
///
2224
/// Reseeding is never strictly *necessary*. Cryptographic PRNGs don't have a
2325
/// limited number of bytes they can output, or at least not a limit reachable
2426
/// in any practical way. There is no such thing as 'running out of entropy'.
@@ -242,4 +244,17 @@ mod test {
242244
assert_eq!(buf, seq);
243245
}
244246
}
247+
248+
#[test]
249+
fn test_clone_reseeding() {
250+
let mut zero = StepRng::new(0, 0);
251+
let rng = ChaChaCore::from_rng(&mut zero).unwrap();
252+
let mut rng1 = ReseedingRng::new(rng, 32*4, zero);
253+
254+
let first: u32 = rng1.gen();
255+
for _ in 0..10 { let _ = rng1.gen::<u32>(); }
256+
257+
let mut rng2 = rng1.clone();
258+
assert_eq!(first, rng2.gen::<u32>());
259+
}
245260
}

0 commit comments

Comments
 (0)