Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
Based on an example provided by Ryan in [1]

[1]: ryankurte#1 (comment)
  • Loading branch information
chrysn committed Nov 25, 2023
1 parent 6d24c80 commit 3070707
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/osrng.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use rand::{RngCore, rngs::OsRng};
use rngcheck::{nist::*, helpers::*};

fn main() {
let mut rng = OsRng;

// Fetch random bytes for tests
let mut a = [0xFF; 100];
rng.fill_bytes(&mut a);

// Check we filled -something- before attempting more in-depth tests
if &a[..2] == &[0xFF; 2] && &a[a.len() - 2..] == &[0xFF; 2] {
panic!("RNG seems to have no-op'ed");
}

// Run NIST frequency checks
println!("Monobit result: {:?}", nist_freq_monobit(BitIter::new(&a)));
println!("Freq block result: {:?}", nist_freq_block(BitIter::new(&a), 10));
}

0 comments on commit 3070707

Please sign in to comment.