pub struct Random {
pub mt: [u32; 624],
pub mti: usize,
}
Expand description
The Random struct is used to generate random numbers using the Mersenne Twister algorithm. It generates pseudorandom integers uniformly distributed in 0..(2^32 - 1) starting from any odd seed in 0..(2^32 - 1).
It contains an array of unsigned 32-bit integers and an index used to generate random numbers. The array contains 624 elements and the index is used to generate random numbers from the array.
The index is incremented after each random number is generated. When the index reaches 624, the array is reinitialized and the index is reset to 0.
Fields§
§mt: [u32; 624]
The array of unsigned 32-bit integers used to generate random numbers
mti: usize
The current index of the array used in the generation of random numbers
Implementations§
source§impl Random
impl Random
sourcepub fn bool(&mut self, probability: f64) -> bool
pub fn bool(&mut self, probability: f64) -> bool
Returns a random bool with a probability that can be set
sourcepub fn bytes(&mut self, len: usize) -> Vec<u8, Global> ⓘ
pub fn bytes(&mut self, len: usize) -> Vec<u8, Global> ⓘ
Returns a vector of random bytes of the given length
sourcepub fn choose<T, 'a>(&'a mut self, values: &'a [T]) -> Option<&'a T>
pub fn choose<T, 'a>(&'a mut self, values: &'a [T]) -> Option<&'a T>
Returns a random element from a slice of values
sourcepub fn int(&mut self, min: i32, max: i32) -> i32
pub fn int(&mut self, min: i32, max: i32) -> i32
Returns a random integer within the given range
sourcepub fn random_range(&mut self, min: u32, max: u32) -> u32
pub fn random_range(&mut self, min: u32, max: u32) -> u32
Returns a random 32-bit unsigned integer within a given range
Trait Implementations§
source§impl Ord for Random
impl Ord for Random
source§impl PartialEq<Random> for Random
impl PartialEq<Random> for Random
source§impl PartialOrd<Random> for Random
impl PartialOrd<Random> for Random
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more