An article on boosting the power of chi-squared test for checking randomness.

Alphabet with in the order of or greater. In chi-squared test, is the number of categories (i.e., is the degree of freedom) and if we apply the test to a random number generator over alphabet , we need a very large sample size.

Chi-square test:

where is the sample size, is the count of samples in category , and is the probability of category according to the hypothesis. Then follows chi-square distribution of degree of freedom asymptotically, namely, the less the more probable the sample fits the distribution . This is a good approximation if for all . Therefore, the necessary (but not sufficient) condition for a good approximation is , depends on the number of categories.

The paper proposes “adaptive chi-squared test” that partition alphabet into subsets which . Therefore, the number of categories are vastly reduced. And we apply chi-squared test on the partition with categories instead of .

The partition of into subsets are as follows: We divide the samples into training samples and testing samples . Then based on training samples, we make alphabets and into the same subset iff the frequency of and are close. In the example of the paper, is partitioned into for alphabets that have zero, one, and more than one occurrences in the training samples, respectively. After the partition, we assign probabilities to subsets according to its constitutient alphabets. In case of the hypothesis of uniform distribution in , then . Such probabilities of the subsets is the null hypothesis in the chi-squared test and we test it using the frequency count in training sample.

Because we combined the categories to make the number of categories reduce from to , we increases the power.

The paper tested the proposal with entropy of encrypted text: Try to distinguished encrypted plain text against random bytes. It assume alphabets to be 24-bit words and partition the set of alphabet into three subsets as mentioned above, and require a level of significant of 5%. For example encrypting English text with AES in block length of 128 bits. The paper found that, in case of 100K samples, the “usual” chi-squared test can detect it is not pure random at 4 out of 40 times but the adaptive chi-squared test can detect 17 out of 40 times. In case of 2000K samples, the usual and adaptive chi-squared test can detect 30 and 33 out of 40 times, respectively. Thus the adaptive test can provide a significant better yield in case of fewer samples.

Note: Such test for randomness is incomplete. For example, it doesn’t tell about the cycling property of random sequences. Wikipedia has an article on randomness tests.

## Bibliographic data

```
@article{
title = "A new test for randomness and its application to some cryptographic problems",
author = "B. Ya. Ryabko and V. S. Stognienko and Yu. I. Shokin",
journal = "Journal of Statistical Planning and Inference",
number = "123",
year = "2004",
pages = "365--376",
doi = "10.1016/S0376-3758(03)-00149-6",
}
```