added observation and z-score to results, emojis

This commit is contained in:
randogoth 2025-01-17 13:27:34 +02:00
parent 10ff2123ac
commit a8c74caf90
19 changed files with 121 additions and 98 deletions

View file

@ -7,10 +7,10 @@ impl Onod {
/// ChiByte randomness test
/// Evaluates the uniformity of byte values across the data and returns a p-value.
pub fn chi_byte(samples: &[u8]) -> f64 {
pub fn chi_byte(samples: &[u8]) -> (f64, f64, f64) {
if samples.is_empty() {
return 0.0; // Default to perfect randomness for empty data
return (-1.0, 0.0, 1.0); // Default to perfect randomness for empty data
}
// Count occurrences of each byte value (0-255)
@ -35,7 +35,12 @@ impl Onod {
let chi_squared_dist = ChiSquared::new(degrees_of_freedom).expect("Failed to create ChiSquared distribution");
let p_value = 1.0 - chi_squared_dist.cdf(chi_squared_stat);
p_value
// Z-score calculation (standardization of the chi-squared statistic)
let mean = degrees_of_freedom; // Mean of the chi-squared distribution
let std_dev = (2.0 * degrees_of_freedom).sqrt(); // Standard deviation of the chi-squared distribution
let z_score = (chi_squared_stat - mean) / std_dev;
(chi_squared_stat, z_score, p_value)
}
}