pub use rand::{rngs::StdRng, Rng, SeedableRng};
use rand::distributions::Standard;
use rand::prelude::Distribution;
#[cfg(feature = "std")]
#[inline(always)]
pub fn get_seeded_rng() -> StdRng {
StdRng::from_entropy()
}
#[cfg(not(feature = "std"))]
#[inline(always)]
pub fn get_seeded_rng() -> StdRng {
const CONST_SEED: u64 = 42;
StdRng::seed_from_u64(CONST_SEED)
}
#[cfg(feature = "std")]
#[inline]
pub fn gen_random<T>() -> T
where
Standard: Distribution<T>,
{
rand::thread_rng().gen()
}
#[cfg(not(feature = "std"))]
#[inline]
pub fn gen_random<T>() -> T
where
Standard: Distribution<T>,
{
use crate::stub::Mutex;
static RNG: Mutex<Option<StdRng>> = Mutex::new(None);
let mut rng = RNG.lock().unwrap();
if rng.is_none() {
*rng = Some(get_seeded_rng());
}
rng.as_mut().unwrap().gen()
}