Struct rug::rand::RandState
[−]
[src]
pub struct RandState<'a> { /* fields omitted */ }
The state of a random number generator.
Methods
impl<'a> RandState<'a>
[src]
fn new() -> RandState<'a>
Creates a new random generator with a compromise between speed and randomness.
fn new_mersenne_twister() -> RandState<'a>
Creates a random generator with a Mersenne Twister algorithm.
fn new_linear_congruential(a: &Integer, c: u32, bits: u32) -> RandState<'a>
Creates a new random generator with a linear congruential algorithm X = (a × X + c) mod 2bits.
fn new_linear_congruential_size(size: u32) -> Option<RandState<'a>>
Creates a new random generator with a linear congruential
algorithm like
new_linear_congruential()
.
a, c and bits are selected from a table such that at
least size bits of each X will be used, that is
2bits ≥ size. The table only has values for a
size of up to 256 bits; None
will be returned if the
requested size is larger.
fn new_custom<'c, T>(custom: &mut T) -> RandState<'c> where
T: 'c + RandGen,
T: 'c + RandGen,
Creates a new custom random generator.
This RandState
is borrowing mutably, so unlike other
instances of RandState
, it cannot be cloned; attempting to
clone will panic.
Examples
use rug::Integer; use rug::rand::{RandGen, RandState}; struct Seed; impl RandGen for Seed { fn gen(&mut self) -> u32 { 0x8cef7310 } } let mut seed = Seed; let mut rand = RandState::new_custom(&mut seed); let mut i = Integer::from(15); i.random_below(&mut rand); println!("0 <= {} < 15", i); assert!(i < 15);
fn seed(&mut self, seed: &Integer)
Seeds the random generator.
fn bits(&mut self, bits: u32) -> u32
Generates a random number with the specified number of bits.
Panics
Panics if bits
is greater than 32.
fn below(&mut self, bound: u32) -> u32
Trait Implementations
impl<'a> Default for RandState<'a>
[src]
impl<'a> Clone for RandState<'a>
[src]
fn clone(&self) -> RandState<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more