Struct bracket_lib::random::RandomNumberGenerator
source · [−]pub struct RandomNumberGenerator { /* private fields */ }
Implementations
sourceimpl RandomNumberGenerator
impl RandomNumberGenerator
sourcepub fn new() -> RandomNumberGenerator
pub fn new() -> RandomNumberGenerator
Creates a new RNG from a randomly generated seed
sourcepub fn seeded(seed: u64) -> RandomNumberGenerator
pub fn seeded(seed: u64) -> RandomNumberGenerator
Creates a new RNG from a specific seed
sourcepub fn rand<T>(&mut self) -> Twhere
Standard: Distribution<T>,
pub fn rand<T>(&mut self) -> Twhere
Standard: Distribution<T>,
Returns a random value of whatever type you specify
sourcepub fn range<T>(&mut self, min: T, max: T) -> Twhere
T: SampleUniform + PartialOrd<T>,
pub fn range<T>(&mut self, min: T, max: T) -> Twhere
T: SampleUniform + PartialOrd<T>,
Returns a random value in the specified range, of type specified at the call site. This is INCLUSIVE of the first parameter, and EXCLUSIVE of the second. So range(1,6) will give you numbers from 1 to 5.
sourcepub fn roll_dice(&mut self, n: i32, die_type: i32) -> i32
pub fn roll_dice(&mut self, n: i32, die_type: i32) -> i32
Rolls dice, using the classic 3d6 type of format: n is the number of dice, die_type is the size of the dice.
sourcepub fn roll(&mut self, dice: DiceType) -> i32
pub fn roll(&mut self, dice: DiceType) -> i32
Rolls dice based on a DiceType struct, including application of the bonus
sourcepub fn roll_str<S>(&mut self, dice: S) -> Result<i32, DiceParseError>where
S: ToString,
pub fn roll_str<S>(&mut self, dice: S) -> Result<i32, DiceParseError>where
S: ToString,
Rolls dice based on passing in a string, such as roll_str(“1d12”)
sourcepub fn random_slice_index<T>(&mut self, slice: &[T]) -> Option<usize>
pub fn random_slice_index<T>(&mut self, slice: &[T]) -> Option<usize>
Returns a random index into a slice
sourcepub fn random_slice_entry<T>(&mut self, slice: &'a [T]) -> Option<&'a T>
pub fn random_slice_entry<T>(&mut self, slice: &'a [T]) -> Option<&'a T>
Returns a random entry in a slice (or none if empty)
sourcepub fn get_rng(&mut self) -> &mut XorShiftRng
pub fn get_rng(&mut self) -> &mut XorShiftRng
Get underlying RNG implementation for use in traits / algorithms exposed by
other crates (eg. rand
itself)
Trait Implementations
sourceimpl Clone for RandomNumberGenerator
impl Clone for RandomNumberGenerator
sourcefn clone(&self) -> RandomNumberGenerator
fn clone(&self) -> RandomNumberGenerator
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more