/// [1]: D. J. Bernstein, [*ChaCha, a variant of
/// Salsa20*](http://cr.yp.to/chacha.html)
+#[deriving(Copy)]
pub struct ChaChaRng {
buffer: [u32, ..STATE_WORDS], // Internal buffer of output
state: [u32, ..STATE_WORDS], // Initial state
index: uint, // Index into state
}
-impl Copy for ChaChaRng {}
-
static EMPTY: ChaChaRng = ChaChaRng {
buffer: [0, ..STATE_WORDS],
state: [0, ..STATE_WORDS],
//! The exponential distribution.
-use core::kinds::Copy;
use core::num::Float;
use {Rng, Rand};
/// Generate Normal Random
/// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield
/// College, Oxford
+#[deriving(Copy)]
pub struct Exp1(pub f64);
-impl Copy for Exp1 {}
-
// This could be done via `-rng.gen::<f64>().ln()` but that is slower.
impl Rand for Exp1 {
#[inline]
/// let v = exp.ind_sample(&mut rand::task_rng());
/// println!("{} is from a Exp(2) distribution", v);
/// ```
+#[deriving(Copy)]
pub struct Exp {
/// `lambda` stored as `1/lambda`, since this is what we scale by.
lambda_inverse: f64
}
-impl Copy for Exp {}
-
impl Exp {
/// Construct a new `Exp` with the given shape parameter
/// `lambda`. Panics if `lambda <= 0`.
//! The normal and derived distributions.
-use core::kinds::Copy;
use core::num::Float;
use {Rng, Rand, Open01};
/// Generate Normal Random
/// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield
/// College, Oxford
+#[deriving(Copy)]
pub struct StandardNormal(pub f64);
-impl Copy for StandardNormal {}
-
impl Rand for StandardNormal {
fn rand<R:Rng>(rng: &mut R) -> StandardNormal {
#[inline]
/// let v = normal.ind_sample(&mut rand::task_rng());
/// println!("{} is from a N(2, 9) distribution", v)
/// ```
+#[deriving(Copy)]
pub struct Normal {
mean: f64,
std_dev: f64,
}
-impl Copy for Normal {}
-
impl Normal {
/// Construct a new `Normal` distribution with the given mean and
/// standard deviation.
/// let v = log_normal.ind_sample(&mut rand::task_rng());
/// println!("{} is from an ln N(2, 9) distribution", v)
/// ```
+#[deriving(Copy)]
pub struct LogNormal {
norm: Normal
}
-impl Copy for LogNormal {}
-
impl LogNormal {
/// Construct a new `LogNormal` distribution with the given mean
/// and standard deviation.
///
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
/// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
+#[deriving(Copy)]
pub struct IsaacRng {
cnt: u32,
rsl: [u32, ..RAND_SIZE_UINT],
c: u32
}
-impl Copy for IsaacRng {}
-
static EMPTY: IsaacRng = IsaacRng {
cnt: 0,
rsl: [0, ..RAND_SIZE_UINT],
///
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
/// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
+#[deriving(Copy)]
pub struct Isaac64Rng {
cnt: uint,
rsl: [u64, .. RAND_SIZE_64],
c: u64,
}
-impl Copy for Isaac64Rng {}
-
static EMPTY_64: Isaac64Rng = Isaac64Rng {
cnt: 0,
rsl: [0, .. RAND_SIZE_64],
#[cfg(not(test))]
mod std {
pub use core::{option, fmt}; // panic!()
+ pub use core::kinds;
}
#[cfg(test)]
/// Reseed an RNG using a `Default` instance. This reseeds by
/// replacing the RNG with the result of a `Default::default` call.
+#[deriving(Copy)]
pub struct ReseedWithDefault;
-impl Copy for ReseedWithDefault {}
-
impl<R: Rng + Default> Reseeder<R> for ReseedWithDefault {
fn reseed(&mut self, rng: &mut R) {
*rng = Default::default();