Struct mini_functions::random::Random
source · #[non_exhaustive]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 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 (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.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> ⓘ
pub fn bytes(&mut self, len: usize) -> Vec<u8> ⓘ
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 uint(&mut self, min: u32, max: u32) -> u32
pub fn uint(&mut self, min: u32, max: u32) -> u32
Returns a random unsigned 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 for Random
impl PartialEq for Random
source§impl PartialOrd for Random
impl PartialOrd 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 moreimpl Eq for Random
impl StructuralEq for Random
impl StructuralPartialEq for Random
Auto Trait Implementations§
impl RefUnwindSafe for Random
impl Send for Random
impl Sync for Random
impl Unpin for Random
impl UnwindSafe for Random
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
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.