1 #[cfg(not(feature = "fuzztarget"))]
3 use rand::{thread_rng,Rng};
4 use bitcoin::util::uint::Uint256;
6 pub fn fill_bytes(data: &mut [u8]) {
7 let mut rng = thread_rng();
11 pub fn rand_uint256() -> Uint256 {
12 let mut rng = thread_rng();
13 Uint256([rng.gen(), rng.gen(), rng.gen(), rng.gen()])
16 pub fn rand_f32() -> f32 {
17 let mut rng = thread_rng();
21 #[cfg(not(feature = "fuzztarget"))]
22 pub use self::real_rng::*;
24 #[cfg(feature = "fuzztarget")]
26 use bitcoin::util::uint::Uint256;
29 static mut RNG_ITER: u64 = 0;
31 pub fn fill_bytes(data: &mut [u8]) {
32 let rng = unsafe { RNG_ITER += 1; RNG_ITER -1 };
33 for i in 0..data.len() / 8 {
34 data[i*8..(i+1)*8].copy_from_slice(&byte_utils::be64_to_array(rng));
36 let rem = data.len() % 8;
37 let off = data.len() - rem;
38 data[off..].copy_from_slice(&byte_utils::be64_to_array(rng)[0..rem]);
41 pub fn rand_uint256() -> Uint256 {
42 let rng = unsafe { RNG_ITER += 1; RNG_ITER - 1 };
43 Uint256([rng, rng, rng, rng])
46 pub fn rand_f32() -> f32 {
47 let rng = unsafe { RNG_ITER += 1; RNG_ITER - 1 };
48 f64::from_bits(rng) as f32
51 pub fn reset_rng_state() {
52 unsafe { RNG_ITER = 0; }
55 #[cfg(feature = "fuzztarget")]
56 pub use self::fuzzy_rng::*;