Rust port of Paul Uszak's new randomness testing suite for TRNG Makers
generating in the sub 1 MB space. Successor to John Walker’s venerable `ent`.
Pipe binary entropy data into the `onod3000` command line tool or call it
with `-f <filename>` to load entropy from a file.
```
`Onod3000` provides multiple randomness tests, each outputting a statistic, a z-score andd a p-value to assess the conformity of the data to random behavior.
All tests have been carefully ported from [Paul Uszak's Java code](http://www.reallyreallyrandom.com/gitbucketlabhub/) (ent3000-0.6.0-beta). Java libraries were substituted with Rust crate equivalents when possible. The suite includes the following tests:
- **Monobit Test**: Evaluates the balance of 0s and 1s.
- **Chi-Square Tests**: Tests the uniformity of bits and bytes.
- **MeanByte Test**: Checks if the mean byte value aligns with expected randomness.
- **Kolmogorov-Smirnov (KS) Test**: Assesses uniformity of data distribution.
- **Pi Test**: Uses Monte Carlo methods to approximate π.
- **Shells Test**: Analyzes distances in 3D space.
- **Gaps Test**: Measures gaps between occurrences of a specific value.
- **Avalanche Test**: Analyzes bit-level changes in data chunks.
- **Runs and RunUps Tests**: Checks for sequential patterns in data.
- **Prediction Test**: Assesses the predictability of next bits.
- **UnCorrelation Test**: Evaluates correlation between shifted data.
More details on some individual tests [available here](http://www.reallyreallyrandom.com/ent3000/the-tests/index.html)
To test the implementation three files of binary random data have been analyzed using the original Java program (version 0.6.0-beta) and this Rust port, expecting the same p-values. The test files can be found in the test folder.
Although the implementation of the randomness tests closely follows the original Java logic, the Kolmogorov-Smirnov test deliberately differs. The Java version compares the data against a pseudo-random uniform sample, which makes the p-value change from run to run for the same input. This port instead runs a one-sample KS test of the byte values against the exact discrete uniform distribution over 0..255, with p-values from the asymptotic Kolmogorov distribution (Stephens' small-sample correction). The result is deterministic and calibrated: on `/dev/urandom` it fails about 1% of the time at alpha = 0.01, slightly less on small inputs because the discrete null makes the test a little conservative.
All other differences are generally negligible for practical purposes and do not affect the overall functionality or statistical significance of the tests.
This work was made possible with the invaluable assistance of OpenAI's ChatGPT, which provided guidance, debugging help, and inspiration throughout the development process.