[][src]Struct rustmt::MT

pub struct MT { /* fields omitted */ }

Contains state of PRNG

Methods

impl MT[src]

pub fn new() -> MT[src]

Create new PRNG seeded with the current timestamp

pub fn from_seed(seed: u64) -> MT[src]

Creates a new generator seeded with the given seed

pub fn seed(&mut self, seed: u64)[src]

Seed the generator

Newly created MTs are seeded with the current timestamp.

pub fn next(&mut self) -> u64[src]

Interpolate the next integer using MT19937

This method should not be used for generating random numbers within a specific range. For that use any of the methods prefixed with "rand".

pub fn rand_f32(&mut self) -> f32[src]

Generate an f32 between 0.0 and 1.0

Example

let mut gen = rustmt::MT::new();
let n = gen.rand_f32();
 
assert!( n >= 0.0 );
assert!( n <= 1.0 );

pub fn rand_f64(&mut self) -> f64[src]

Generate an f64 between 0.0 and 1.0

Example

let mut gen = rustmt::MT::new();
let n = gen.rand_f64();
 
assert!( n >= 0.0 );
assert!( n <= 1.0 );

pub fn rand_i32(&mut self, start: i32, end: i32) -> i32[src]

Generate an i32 between start-end-1 inclusive

Example

let mut gen = rustmt::MT::new();
let n = gen.rand_i32( 1, 3 );
 
assert!( n >= 1 );
assert!( n < 3 );

Panics

When start is greater than or equal to end

pub fn rand_i64(&mut self, start: i64, end: i64) -> i64[src]

Generate an i64 between start-end-1 inclusive

Example

let mut gen = rustmt::MT::new();
let n = gen.rand_i64( 1, 3 );
 
assert!( n >= 1 );
assert!( n < 3 );

Panics

When start is greater than or equal to end

pub fn rand_usize(&mut self, end: usize) -> usize[src]

Generate a usize less than end

Example

let mut gen = rustmt::MT::new();
 
let v = vec![ 1, 2, 3, ];
let n = gen.rand_usize( v.len() );
 
assert!( n < v.len() );

pub fn shuffle<T>(&mut self, v: &mut Vec<T>)[src]

Shuffle the given vector

Example

let mut gen = rustmt::MT::new();
 
let mut people = vec![ "Logan", "Trent", "Cameron", "David", ];
gen.shuffle( &mut people );
 
println!( "Random person = {}", people[0] );

Auto Trait Implementations

impl RefUnwindSafe for MT

impl Send for MT

impl Sync for MT

impl Unpin for MT

impl UnwindSafe for MT

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.