Fix std_rand feature
This commit is contained in:
committed by
morenol
parent
616e38c282
commit
af0a740394
+8
-7
@@ -1,19 +1,20 @@
|
|||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std_rand"))]
|
||||||
pub(crate) use rand::rngs::SmallRng as RngImpl;
|
pub use rand::rngs::SmallRng as RngImpl;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std_rand")]
|
||||||
pub(crate) use rand::rngs::StdRng as RngImpl;
|
pub use rand::rngs::StdRng as RngImpl;
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
|
|
||||||
pub(crate) fn get_rng_impl(seed: Option<u64>) -> RngImpl {
|
/// Custom switch for random fuctions
|
||||||
|
pub fn get_rng_impl(seed: Option<u64>) -> RngImpl {
|
||||||
match seed {
|
match seed {
|
||||||
Some(seed) => RngImpl::seed_from_u64(seed),
|
Some(seed) => RngImpl::seed_from_u64(seed),
|
||||||
None => {
|
None => {
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(feature = "std")] {
|
if #[cfg(feature = "std_rand")] {
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
RngImpl::seed_from_u64(rand::thread_rng().next_u64())
|
RngImpl::seed_from_u64(rand::thread_rng().next_u64())
|
||||||
} else {
|
} else {
|
||||||
// non-std build, use getrandom
|
// no std_random feature build, use getrandom
|
||||||
let mut buf = [0u8; 64];
|
let mut buf = [0u8; 64];
|
||||||
getrandom::getrandom(&mut buf).unwrap();
|
getrandom::getrandom(&mut buf).unwrap();
|
||||||
RngImpl::seed_from_u64(buf[0] as u64)
|
RngImpl::seed_from_u64(buf[0] as u64)
|
||||||
|
|||||||
Reference in New Issue
Block a user