bb_runtime/framework/
rng.rs1pub trait RngU64Source: Send + Sync {
7 fn next_u64(&mut self) -> u64;
9}
10
11#[derive(Default)]
13pub struct GetrandomU64;
14
15impl GetrandomU64 {
16 pub fn new() -> Self {
18 Self
19 }
20}
21
22impl RngU64Source for GetrandomU64 {
23 fn next_u64(&mut self) -> u64 {
24 let mut buf = [0u8; 8];
25 getrandom::getrandom(&mut buf).expect("getrandom");
28 u64::from_le_bytes(buf)
29 }
30}
31
32pub struct CounterRng(pub u64);
34
35impl RngU64Source for CounterRng {
36 fn next_u64(&mut self) -> u64 {
37 let v = self.0;
38 self.0 = self.0.wrapping_add(1);
39 v
40 }
41}
42