1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use rug::rand::{ThreadRandGen, ThreadRandState};
pub trait SecureRng = rand_core::RngCore + rand_core::CryptoRng;
pub struct GeneralRng<R: SecureRng> {
rng_wrapper: RngWrapper<R>,
}
impl<R: SecureRng> GeneralRng<R> {
pub fn new(rng: R) -> Self {
GeneralRng {
rng_wrapper: RngWrapper { rng },
}
}
pub fn rng(&mut self) -> &mut R {
&mut self.rng_wrapper.rng
}
pub fn rug_rng(&mut self) -> ThreadRandState<'_> {
ThreadRandState::new_custom(&mut self.rng_wrapper)
}
}
struct RngWrapper<R: SecureRng> {
rng: R,
}
impl<R: SecureRng> ThreadRandGen for RngWrapper<R> {
fn gen(&mut self) -> u32 {
self.rng.next_u32()
}
}