diff --git a/src/bin/main.rs b/src/bin/main.rs index a6adf64..9abb034 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -36,9 +36,9 @@ fn main() -> io::Result<()> { } println!("\nTesting {} bytes from {}.", input_data.len(), source); - println!("-----------------------------------------------------"); - println!("Randomness Test Observation Z-Score P-Value Pass"); - println!("-----------------------------------------------------"); + println!("--------------------------------------------------------"); + println!("Randomness Test Value Z-Score P-Value Pass"); + println!("--------------------------------------------------------"); let mut passed_tests = 0; let alpha = 0.01; @@ -49,7 +49,6 @@ fn main() -> io::Result<()> { // Run each test with the appropriate handling let tests = [ ("Shannon", Onod::shannon(&input_data)), - ("Sanity", Onod::sanity(&input_data)), ("Monobit", Onod::monobit(&input_data)), ("ChiBit", Onod::chi_bit(&input_data)), ("ChiByte", Onod::chi_byte(&input_data)), @@ -79,7 +78,7 @@ fn main() -> io::Result<()> { }; println!( - "{:<15} {:>15.3} {:>8.4} {:.4} {}", + "{:<15} {:>15.3} {:>8.4} {:>7.4} {:>2}", test_name, observation, z_score, p_value, result ); @@ -88,9 +87,9 @@ fn main() -> io::Result<()> { p_values.push(*p_value); } - println!("-----------------------------------------------------"); + println!("--------------------------------------------------------"); println!("{}/{} tests passed.", passed_tests, tests.len()); - println!("-----------------------------------------------------"); + println!("--------------------------------------------------------"); Ok(()) } \ No newline at end of file diff --git a/src/uniformity/mod.rs b/src/uniformity/mod.rs index 7537ef2..8f0b27c 100644 --- a/src/uniformity/mod.rs +++ b/src/uniformity/mod.rs @@ -10,7 +10,6 @@ pub mod pi; pub mod prediction; pub mod runs; pub mod runups; -pub mod sanity; pub mod shannon; pub mod shells; pub mod uncorrelation; \ No newline at end of file diff --git a/src/uniformity/sanity.rs b/src/uniformity/sanity.rs deleted file mode 100644 index f1875ad..0000000 --- a/src/uniformity/sanity.rs +++ /dev/null @@ -1,36 +0,0 @@ -use crate::Onod; - -impl Onod { - - /// Sanity randomness test - /// Checks for basic properties of randomness and returns a p-value. - pub fn sanity(samples: &[u8]) -> (f64, f64, f64) { - if samples.is_empty() { - return (-1.0, 0.0, 1.0); - } - - // Check the proportion of ones and zeros in the byte data - let mut one_bits = 0; - let mut total_bits = 0; - - for &byte in samples { - one_bits += byte.count_ones(); - total_bits += 8; - } - - let observed_ratio = one_bits as f64 / total_bits as f64; - let expected_ratio = 0.5; // Expected for a truly random sequence - let std_dev = (0.5 * 0.5 / total_bits as f64).sqrt(); // Standard deviation for binomial distribution - - // Z-score calculation - let z_score = (observed_ratio - expected_ratio) / std_dev; - - // Use normal distribution to calculate p-value - use statrs::distribution::{Normal, ContinuousCDF}; - let normal_dist = Normal::new(expected_ratio, std_dev).expect("Failed to create Normal distribution"); - let p_value = 1.0 - normal_dist.cdf(observed_ratio); - - (observed_ratio, z_score, p_value) - } - -} \ No newline at end of file