Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test a random generator

Tags:

random

testing

I need to test a random number generator which produces numbers randomly. How to make sure the numbers generated are random.

like image 482
adsk Avatar asked Jan 25 '10 06:01

adsk


People also ask

How do you test a random distribution?

Hypothesis: To test the run test of randomness, first set up the null and alternative hypothesis. In run test of randomness, null hypothesis assumes that the distributions of the two continuous populations are the same. The alternative hypothesis will be the opposite of the null hypothesis.

How do you know if a random number generator is random?

You can't. It is impossible to verify that the output of a purported random generator is random enough for cryptography. (It is possible to verify that it's random enough for some applications such as Monte Carlo numerical methods, but not, say, to generate a cryptographic key.)

Why is it essential to test the random number generator?

It is necessary to test random numbers because the random numbers we generate are pseudo random numbers and not real and pseudo random number generator must generate a sequence of such random numbers which are uniformly distributed and they should not be correlated, they should not repeat itself.


2 Answers

You can only test statistical randomness anyway, and that does not prove whether the number sequence is cryptographically strong. Statistically testing a PRNG requires quite a lot (10 or even 100Gbytes) of the generated bits.

Dieharder is a very good testing suite.

http://www.phy.duke.edu/~rgb/General/dieharder.php

And TestU01 is also well-known.

http://www.iro.umontreal.ca/~simardr/testu01/tu01.html

like image 66
jj1bdx Avatar answered Sep 26 '22 23:09

jj1bdx


Use chi-square testing. What language are you using? I can offer a C++ example. Basically

  • Place random numbers in buckets (many times).
  • The number of buckets minus one is the degrees of freedom.
  • Compare the bucket tallies against "expected" tallies, yielding a chi-square result.
  • Use a chi-square calculator to see the probability of getting those results.
like image 21
Jon Reid Avatar answered Sep 23 '22 23:09

Jon Reid