pub(crate) mod wyrand;
use self::wyrand::THREAD_WYRAND as THREAD_RNG;
use std::ops::RangeBounds;
use std::stringify;
pub use wyrand::WyRng;
macro_rules! api_impl {
($t:tt,$doc:tt) => {
#[doc = $doc]
#[inline(always)]
pub fn $t() -> $t {
THREAD_RNG.try_with(|rng| rng.$t()).unwrap()
}
};
($t:tt) => {
#[doc = "Returns a random `"]
#[doc = stringify!($t)]
#[doc = "` in the given range(thread-safe, but not cryptographically secure)."]
#[doc = "Panics if the range is invalid."]
#[inline(always)]
pub fn $t(range: impl RangeBounds<$t>) -> $t {
THREAD_RNG.try_with(|rng| rng.$t(range)).unwrap()
}
};
}
api_impl!(
f64,
"Returns a random `f64` in the `[0.0,1.0)`. (thread-safe, but not cryptographically secure)"
);
api_impl!(
f32,
"Returns a random `f32` in the `[0.0,1.0)`. (thread-safe, but not cryptographically secure)"
);
api_impl!(u32);
api_impl!(i32);
api_impl!(u64);
api_impl!(i64);
api_impl!(usize);
api_impl!(isize);