Struct ezra::dice::numeric_die::NumericDie
[−]
[src]
pub struct NumericDie { /* fields omitted */ }
A die that has numeric values at fixed intervals from each other (e.g. d6, d20, d4, etc).
Methods
impl NumericDie
[src]
fn new(min: usize, step: usize, num_sides: usize, rng: Option<Box<Rng>>) -> Self
Pseudo-constructor for NumericDie object.
Parameters
- min : minimum value die may have
- step : interval between values
- num_sides : number of possible values
- rng : optional RNG; if none, defaults to ThreadRng
Return value
A NumericDie constructed with the given specifications
Examples
extern crate rand; use ezra::dice::{Die,NumericDie}; use rand::OsRng; // Create a standard six sided die, using the OS's source of randomness let rng = OsRng::new().unwrap(); let mut die = NumericDie::new(1, 1, 6, Some(Box::new(rng))); println!("First die roll has value: {}", die.roll().get_value());
A die can also be created without specifying an RNG. The constructed die will use its own thread-local RNG by default.
let die = NumericDie::new(1, 1, 6, None);
Trait Implementations
impl Die for NumericDie
[src]
type ValueType = usize
The type of value the die may have.
fn roll(&mut self) -> &mut Self
Randomize the value of the die, selecting from the values specified at die construction. ##### Return value A mutable reference to the Die # Examples Read more
fn get_value(&self) -> Self::ValueType
Obtain a copy of the current value of the die. ##### Return value A copy of the current value of the die # Examples ``` # extern crate ezra; # fn main() { use ezra::dice::{Die,NumericDie}; Read more
fn values(&self) -> Vec<Self::ValueType>
Obtain a vector of all possile values the die may take. ##### Return value A vector of all possible values the die may have # Examples ``` # extern crate ezra; # fn main() { use ezra::dice::{Die,NumericDie}; Read more