use crate::{Box, Rand};
#[doc = crate::_tags!(rand)]
#[doc = crate::_doc_location!("num/prob/rand")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
pub trait RandAlloc: Rand {
fn rand_seed_from_heap() -> Self;
}
impl RandAlloc for crate::Pcg32 {
#[inline(never)]
fn rand_seed_from_heap() -> Self {
let (a, b) = (0, Box::new(0));
let (state, inc): (u64, u64) = (&a as *const _ as u64, &b as *const _ as u64 | 1);
Self::new_unchecked(state, inc)
}
}
impl RandAlloc for crate::XorShift128p {
#[inline(never)]
fn rand_seed_from_heap() -> Self {
let (a, b) = (0, Box::new(0));
let seed: [u64; 2] = [&a as *const _ as u64, &b as *const _ as u64];
Self::new_unchecked(seed)
}
}
#[cfg(feature = "rand")]
impl RandAlloc for crate::Xoroshiro128pp {
#[inline(never)]
fn rand_seed_from_heap() -> Self {
let (a, b, c, d) = (0, Box::new(0), Box::new(0), 0);
let seed: [u32; 4] = [
&a as *const _ as u32,
&b as *const _ as u32,
&c as *const _ as u32,
&d as *const _ as u32,
];
Self::new_unchecked(seed)
}
}