File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ use rand_core::impls::BlockRng;
19
19
/// A wrapper around any PRNG which reseeds the underlying PRNG after it has
20
20
/// generated a certain number of random bytes.
21
21
///
22
+ /// When the RNG gets cloned, the clone is reseeded on first use.
23
+ ///
22
24
/// Reseeding is never strictly *necessary*. Cryptographic PRNGs don't have a
23
25
/// limited number of bytes they can output, or at least not a limit reachable
24
26
/// in any practical way. There is no such thing as 'running out of entropy'.
@@ -242,4 +244,17 @@ mod test {
242
244
assert_eq ! ( buf, seq) ;
243
245
}
244
246
}
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
+ }
245
260
}
You can’t perform that action at this time.
0 commit comments