1 #[cfg(not(feature = "fuzztarget"))]
3 use rand::{thread_rng,Rng};
5 pub fn fill_bytes(data: &mut [u8]) {
6 let mut rng = thread_rng();
10 pub fn rand_u832() -> [u8; 32] {
11 let mut res = [0; 32];
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")]
28 static mut RNG_ITER: u64 = 0;
30 pub fn fill_bytes(data: &mut [u8]) {
31 let rng = unsafe { RNG_ITER += 1; RNG_ITER -1 };
32 for i in 0..data.len() / 8 {
33 data[i*8..(i+1)*8].copy_from_slice(&byte_utils::be64_to_array(rng));
35 let rem = data.len() % 8;
36 let off = data.len() - rem;
37 data[off..].copy_from_slice(&byte_utils::be64_to_array(rng)[0..rem]);
40 pub fn rand_u832() -> [u8; 32] {
41 let rng = unsafe { RNG_ITER += 1; RNG_ITER - 1 };
42 let mut res = [0; 32];
43 let data = byte_utils::le64_to_array(rng);
44 res[8*0..8*1].copy_from_slice(&data);
45 res[8*1..8*2].copy_from_slice(&data);
46 res[8*2..8*3].copy_from_slice(&data);
47 res[8*3..8*4].copy_from_slice(&data);
51 pub fn rand_f32() -> f32 {
52 let rng = unsafe { RNG_ITER += 1; RNG_ITER - 1 };
53 f64::from_bits(rng) as f32
56 pub fn reset_rng_state() {
57 unsafe { RNG_ITER = 0; }
60 #[cfg(feature = "fuzztarget")]
61 pub use self::fuzzy_rng::*;