Add AesRng::fork convenience method
@@ -12,6 +12,7 @@ use core::arch::x86_64::*;
use core::fmt;
use rand_core::block::{BlockRng, BlockRngCore};
use rand_core::{CryptoRng, Error, RngCore, SeedableRng};
+use rand::Rng;
/// Implementation of a random number generator based on fixed-key AES.
///
@@ -62,6 +63,13 @@ impl AesRng {
let seed = rand::random::<Block>();
AesRng::from_seed(seed)
}
+
+ /// Create a new RNG using a random seed from this one.
+ #[inline]
+ pub fn fork(&mut self) -> Self {
+ let seed = self.gen::<Block>();
+ AesRng::from_seed(seed)
+ }
}
impl Default for AesRng {
