remove OsRng from sample/src/source.rs

This commit is contained in:
Janmajaya Mall
2025-07-04 17:56:30 +05:30
parent 30b5edc536
commit 2a5e0e7dc3

View File

@@ -1,6 +1,6 @@
use rand_chacha::ChaCha8Rng; use rand_chacha::ChaCha8Rng;
use rand_chacha::rand_core::SeedableRng; use rand_chacha::rand_core::SeedableRng;
use rand_core::{OsRng, RngCore, TryRngCore}; use rand_core::RngCore;
const MAXF64: f64 = 9007199254740992.0; const MAXF64: f64 = 9007199254740992.0;
@@ -8,12 +8,6 @@ pub struct Source {
source: ChaCha8Rng, source: ChaCha8Rng,
} }
pub fn new_seed() -> [u8; 32] {
let mut seed = [0u8; 32];
OsRng.try_fill_bytes(&mut seed).unwrap();
seed
}
impl Source { impl Source {
pub fn new(seed: [u8; 32]) -> Source { pub fn new(seed: [u8; 32]) -> Source {
Source { Source {
@@ -21,14 +15,11 @@ impl Source {
} }
} }
pub fn new_seed(&mut self) -> [u8; 32] {
let mut seed: [u8; 32] = [0u8; 32];
self.source.fill_bytes(&mut seed);
seed
}
pub fn branch(&mut self) -> Self { pub fn branch(&mut self) -> Self {
Source::new(self.new_seed()) let mut seed = [0; 32];
self.source.fill_bytes(&mut seed);
Source::new(seed)
} }
#[inline(always)] #[inline(always)]