22 lines
558 B
Rust
22 lines
558 B
Rust
use ::rand_core::SeedableRng;
|
|
|
|
/// Seed an RNG with system provided randomness.
|
|
pub fn seed_rng<R: SeedableRng>() -> R {
|
|
#[cfg(ableOS)] {
|
|
let seed = unsafe {
|
|
let seed_a = crate::syscalls::get_random();
|
|
let seed_b = crate::syscalls::get_random();
|
|
(seed_a as u64) << 32 | seed_b as u64
|
|
};
|
|
R::seed_from_u64(seed)
|
|
}
|
|
#[cfg(not(ableOS))] {
|
|
R::from_entropy()
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "pcg_rng")]
|
|
pub fn obtain_rng() -> impl ::rand_core::RngCore {
|
|
seed_rng::<::rand_pcg::Pcg32>()
|
|
}
|