25 lines
646 B
Rust
25 lines
646 B
Rust
//! The random number generator, using a mutex to share the instance
|
|
use std::sync::Mutex;
|
|
|
|
use ::bracket_lib::prelude::*;
|
|
use ::lazy_static::lazy_static;
|
|
|
|
lazy_static! {
|
|
static ref RNG: Mutex<RandomNumberGenerator> = Mutex::new(RandomNumberGenerator::new());
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn reseed(seed: u64) {
|
|
*RNG.lock().unwrap() = RandomNumberGenerator::seeded(seed);
|
|
}
|
|
|
|
/// Rolls `n` dice, with `die_type` sides
|
|
pub fn roll_dice(n: i32, die_type: i32) -> i32 {
|
|
RNG.lock().unwrap().roll_dice(n, die_type)
|
|
}
|
|
|
|
/// Returns a number in the range given
|
|
pub fn range(min: i32, max: i32) -> i32 {
|
|
RNG.lock().unwrap().range(min, max)
|
|
}
|