Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the past I have used the Chi-squared test to check the statistical randomness of my generator. Is this a good test to use? Are there other tests?

share|improve this question
There are no tests that can prove your PRNG works random - only those that can prove the opposite. – asd Aug 27 '11 at 21:21
@asd To be pedantic, a test suite can show overwhelming probability that a number stream is from a bad PRNG/DRBG, no amount of testing can prove that it isn't random, it can suggest it very strongly. Dieharder for example is created with the knowledge in mind that it may take a lot of testing before you can show the PRNG is probably not random. Likewise, only testing 10MB of data may give you the false impression that true random isn't just that. – Iam Nick Feb 29 at 19:53
up vote 11 down vote accepted

Section 5.4 "Statistical tests" of Handbook of Applied Cryptography lists several such tests. However, note that if you're after a provably secure PRNG, such tests are far from being perfect.

For a provably secure PRNG, you need to formally prove the indistinguishability of its output from a truly-random sequence. See chapter 3 of Foundations of Cryptography for more info.

share|improve this answer

Checking statistical randomness is a semi-good test. What I mean by that is that if a given PRNG does not look good statistically, then it is utterly proven to be pure junk. On the other hand, good statistical randomness does not tell you much with regards to cryptographic security. Cryptographic security is about whether the PRNG output could be predicted by a sentient attacker who knows the in and outs of your algorithm (but not its internal state). Statistical randomness is about whether the PRNG output could be predicted by a trained monkey.

"Diehard tests" used to be popular for testing non-cryptographic PRNG. During the AES competition (a dozen years ago), NIST ran them on all AES candidates, and found nothing, and the general opinion among cryptographers was that it was mostly a waste of time.

A Linear Feedback Shift Register has handsome results with Diehard -- and using it for cryptography is immediate failure.

share|improve this answer
Are you saying that verification of the design should be sufficient and that statistical tests are insufficient to verify operation? – this.josh Aug 13 '11 at 4:44
It does not harm to run statistical tests; if they detect a bias then you can forget your design, and restart from scratch. But almost all weak designs will pass the tests with no bias. To verify if a cryptographic algorithm is secure, the only known efficient test is to have at least a few dozen cryptographers try to break it for a few years. – Thomas Pornin Aug 13 '11 at 4:49
NIST has its own test suite, called "Statistical Test Suite" (STS). It is downloadable from – M.S. Dousti Apr 23 '12 at 19:36
dieharder includes the diehard tests and can be run easily on Ubuntu without compiling or anything. – endolith May 1 '12 at 15:42

What tests can I do to ensure my PRNG is working correctly?

That depends on what exactly you mean by “working correctly”.

You can do statistical tests to check for various statistical flaws your random number generator might be subject to, but you have be aware of the fact that statistical testing cannot serve as a substitute for cryptanalysis… meaning: when it comes to cryptographic security, you’ll have to dive into cryptanalysis, like I described in another answer to a somewhat related question.

Are there other tests?

Of course… besides the Chi-squared test you already know and mentioned in your question, there are whole batteries of statistical tests available! All you have to do is to pick your favorite poison:

There might be other solutions out there which may or may not be interesting to look at, but – to limit the scope to a usable level – I decided to only mention some of the (more prominent) statistical test suites.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.