Struct rug::rand::RandState [] [src]

pub struct RandState<'a> { /* fields omitted */ }

The state of a random number generator.

Methods

impl<'a> RandState<'a>
[src]

Creates a new random generator with a compromise between speed and randomness.

Creates a random generator with a Mersenne Twister algorithm.

Creates a new random generator with a linear congruential algorithm X = (a × X + c) mod 2bits.

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 2bitssize. The table only has values for a size of up to 256 bits; None will be returned if the requested size is larger.

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);

Seeds the random generator.

Generates a random number with the specified number of bits.

Panics

Panics if bits is greater than 32.

Generates a random number below the given boundary value.

This function can never return the maximum 32-bit value; in order to generate a 32-bit random value that covers the whole range, use the bits() with bits set to 32.

Panics

Panics if the boundary value is zero.

Trait Implementations

impl<'a> Default for RandState<'a>
[src]

Returns the "default value" for a type. Read more

impl<'a> Clone for RandState<'a>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> Drop for RandState<'a>
[src]

A method called when the value goes out of scope. Read more

impl<'a> Send for RandState<'a>
[src]

impl<'a> Sync for RandState<'a>
[src]