From 206f0127291fe56f5c28ade60f99faf464fa031b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 3 Feb 2022 12:01:17 -0500 Subject: [PATCH] Add new rng module --- src/main.rs | 1 + src/rng.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/rng.rs diff --git a/src/main.rs b/src/main.rs index 1b7079f..62e0c8b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ mod random_table; mod raws; mod rect; mod rex_assets; +mod rng; mod saveload_system; mod spatial; mod spawner; diff --git a/src/rng.rs b/src/rng.rs new file mode 100644 index 0000000..b942b92 --- /dev/null +++ b/src/rng.rs @@ -0,0 +1,18 @@ +use ::rltk::prelude::*; +use std::sync::Mutex; + +lazy_static! { + static ref RNG: Mutex = 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) +}