pub struct Random { /* private fields */ }
Implementations§
Source§impl Random
impl Random
pub fn new(seed: u64) -> Self
Sourcepub fn next(&mut self, bits: u8) -> i32
pub fn next(&mut self, bits: u8) -> i32
Steps the RNG, returning up to 48 bits.
§Panics
If the amount of requested bits is over 48, this function panics. Use next_i64/next_u64 instead, or multiple calls.
Sourcepub fn next_bytes(&mut self, bytes: &mut [u8])
pub fn next_bytes(&mut self, bytes: &mut [u8])
Fills the byte array with random bytes.
Sourcepub fn next_i32_bound(&mut self, max: i32) -> i32
pub fn next_i32_bound(&mut self, max: i32) -> i32
Returns a positive random number in the range [0, max), up to 2^31.
The range of the return value is represented by the value 0 <= value < max
.
A maximum of less than 1 is invalid because then no value would satisfy the range.
§Panics
If max
is less than 1, the function panics.
Sourcepub fn next_u32_bound(&mut self, max: u32) -> u32
pub fn next_u32_bound(&mut self, max: u32) -> u32
Returns a positive random number in the range [0, max), up to 2^31.
The range of the return value is represented by the value 0 <= value < max
.
A maximum of 0 is invalid because then no value would satisfy the range.
Maximums of 2^31 or greater are not supported in Java.
§Panics
If max
reinterpreted as a signed 32-bit integer is less than 1, the function panics.
Sourcepub fn next_bool(&mut self) -> bool
pub fn next_bool(&mut self) -> bool
Returns a boolean value that has an equal chance of being true or false.
Sourcepub fn next_gaussian(&mut self) -> f64
pub fn next_gaussian(&mut self) -> f64
Returns a gaussian-distributed number with a mean of 0.0 and standard deviation of 1.0.