Add new rng module

This commit is contained in:
Timothy Warren 2022-02-03 12:01:17 -05:00
parent 161ed3f4b9
commit 206f012729
2 changed files with 19 additions and 0 deletions

View File

@ -18,6 +18,7 @@ mod random_table;
mod raws;
mod rect;
mod rex_assets;
mod rng;
mod saveload_system;
mod spatial;
mod spawner;

18
src/rng.rs Normal file
View File

@ -0,0 +1,18 @@
use ::rltk::prelude::*;
use std::sync::Mutex;
lazy_static! {
static ref RNG: Mutex<RandomNumberGenerator> = Mutex::new(RandomNumberGenerator::new());
}
pub fn reseed(seed: u64) {
*RNG.lock().unwrap() = RandomNumberGenerator::seeded(seed);
}
pub fn roll_dice(n: i32, die_type: i32) -> i32 {
RNG.lock().unwrap().roll_dice(n, die_type)
}
pub fn range(min: i32, max: i32) -> i32 {
RNG.lock().unwrap().range(min, max)
}