Randomness Testing Guide

Block Longest Run Test

In the NIST paper A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications, the authors propose the Test for the Longest Run of Ones in a Block. The idea is to slice the binary string into blocks and check for the longest run of 1s within each block.

This overall idea of the test makes sense, but the way they implemented it involves arbitrary thresholds and magic numbers. For example, if nn is the length of the bit string and MM is the block size, then the following table specifies the proper way of sizing MM as a function of nn.

Minimum nnMM
1288
6272128
750,00010410^4

Where did the magic numbers 128, 6272, and 750,000 come from? What happens if nn is a much larger number, like 10,000,000?

The more serious problems arise when considering the table of expected counts for the chi-squared test.

viv_iM=8M = 8M=128M = 128M=104M = 10^4
v0v_01\leq 14\leq 410\leq 10
v1v_12511
v2v_23612
v3v_34\geq 4713
v4v_4814
v5v_59\geq 915
v6v_616\geq 16

Why is the number of categories different depending on the value of MM? Thankfully, the authors specify what the probabilities are in a later section, but they don't provide the formula for how the numbers were obtained, instead citing a 397-page non-free-access book without saying which page the formula came from.

The benefit of using the "runs test" described on this website is that it avoids the need for arbitrary thresholding and doesn't require knowing or computing any of those magic numbers. Although the two tests are not strictly equivalent, they tend to succeed and fail on the same test cases, which indicates that they serve roughly the same purpose.

Both tests successfully catch the alternating zeros and ones test case.

Alternating Zeros and Ones0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

Both tests fail to catch the expected runs test case.

Expected Runs Distribution0100110100011101001101000011110100110100011101001101000001111101001101000111010011010000111101001101