use core::prelude::*;
use core::num::Int;
-
use {Rng, SeedableRng, Rand};
const KEY_WORDS : uint = 8; // 8 words for the 256-bit key
///
/// [1]: D. J. Bernstein, [*ChaCha, a variant of
/// Salsa20*](http://cr.yp.to/chacha.html)
-
-#[derive(Copy)]
+#[deriving(Copy, Clone)]
pub struct ChaChaRng {
buffer: [u32; STATE_WORDS], // Internal buffer of output
state: [u32; STATE_WORDS], // Initial state
}
}
+// Cannot be derived because [u32; 256] does not implement Clone
+impl Clone for IsaacRng {
+ fn clone(&self) -> IsaacRng {
+ *self
+ }
+}
+
impl Rng for IsaacRng {
#[inline]
fn next_u32(&mut self) -> u32 {
}
}
+// Cannot be derived because [u32; 256] does not implement Clone
+impl Clone for Isaac64Rng {
+ fn clone(&self) -> Isaac64Rng {
+ *self
+ }
+}
+
impl Rng for Isaac64Rng {
// FIXME #7771: having next_u32 like this should be unnecessary
#[inline]
}
}
+
#[cfg(test)]
mod test {
use std::prelude::v1::*;
/// RNGs"](http://www.jstatsoft.org/v08/i14/paper). *Journal of
/// Statistical Software*. Vol. 8 (Issue 14).
#[allow(missing_copy_implementations)]
+#[deriving(Clone)]
pub struct XorShiftRng {
x: u32,
y: u32,
w: u32,
}
-impl Clone for XorShiftRng {
- fn clone(&self) -> XorShiftRng {
- XorShiftRng {
- x: self.x,
- y: self.y,
- z: self.z,
- w: self.w,
- }
- }
-}
-
impl XorShiftRng {
/// Creates a new XorShiftRng instance which is not seeded.
///
#[cfg(not(test))]
mod std {
pub use core::{option, fmt}; // panic!()
+ pub use core::clone; // derive Clone
pub use core::kinds;
}
/// The standard RNG. This is designed to be efficient on the current
/// platform.
-#[derive(Copy)]
+#[deriving(Copy, Clone)]
pub struct StdRng {
rng: IsaacWordRng,
}
type ThreadRngInner = reseeding::ReseedingRng<StdRng, ThreadRngReseeder>;
/// The thread-local RNG.
+#[deriving(Clone)]
pub struct ThreadRng {
rng: Rc<RefCell<ThreadRngInner>>,
}