pub struct MT { /* private fields */ }
Expand description
Contains state of PRNG
Implementations§
Source§impl MT
impl MT
Sourcepub fn seed(&mut self, seed: u64)
pub fn seed(&mut self, seed: u64)
Seed the generator
Newly created MTs are seeded with the current timestamp.
Sourcepub fn next(&mut self) -> u64
pub fn next(&mut self) -> u64
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”.
Sourcepub fn rand_f32(&mut self) -> f32
pub fn rand_f32(&mut self) -> f32
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 );
Sourcepub fn rand_f64(&mut self) -> f64
pub fn rand_f64(&mut self) -> f64
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 );
Sourcepub fn rand_usize(&mut self, end: usize) -> usize
pub fn rand_usize(&mut self, end: usize) -> usize
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() );
Auto Trait Implementations§
impl Freeze for MT
impl RefUnwindSafe for MT
impl Send for MT
impl Sync for MT
impl Unpin for MT
impl UnwindSafe for MT
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more