A single, good test for a random number generator?

445 Views Asked by At

I'm chasing a bug in the RNG for a well-known programming language under certain pathological inputs. There is an obvious pattern in this pathological case, apparent with very small n (~ 10000), and the input fails the dieharder tests (of course).

I am writing a unit test to catch this bug. I need to implement a statistical test to demonstrate this bug exists, but the test needs to be quick and ideally easy to implement in my target language. Unfortunately, I'm not familiar with the dieharder tests, specifically or with any statistical tests for RNG, generally.

Is there a quick test for randomness that can catch obviously non-random sequences of small sets?

PS: The problem is not in the RNG implementation (Mersenne Twister). The problem lay in the formula applied to the random number to fit it into a user-specified range. I don't have access to the formula from user-land, so I can't just unit test that formula (which is what I want to do). The only exposed interface is that of a RNG, so I figure I will test it as a RNG.

2

There are 2 best solutions below

0
On BEST ANSWER

Using NIST Standard 800-22, "A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications", I can use Hamming Weight as the basis for a spectral test. That is good enough to expose the bug.

0
On

I suggest that you check "The Art of Computer Programming", Vol. 2 (Seminumerical Algorithms), by Donald E. Knuth. Chapter 3 is completely devoted to random number generators, and tests to determine randomness. You will find many tests that you can apply to your data. I would recommend the Fourier test, which has yielded good results for me. Nevertheless, I warn you that sometimes it may be difficult to decide that a sequence is non-random.