views:

1163

answers:

7

i have written in matlab, a program, which is supossed to generate random numbers between 0 and 1. i have test it only with the runstest in matlab, and te result is that the sequence is random. i have seen the histograms too, and they have a beta distribution. i want to test this rng whith other test, such as diehard, ent, or nist, but i don't know how. can someone explain how to use them, or suggest me some other randomness tests. thank you

A: 

Confine the result to a specific range (possibly using the mod operator), run your code a few million times and count how many times you see each number in the range. Make sure the counts are roughly the same, and that you don't have a bias for any specific values.

Joel Coehoorn
That's kind of a monobit test. But still very short of a real test suite like the ones he mentioned (ok, ent doesn't count).
Joey
Good start. Next up is to generate ordered pairs and see that they are evenly distributed in the plane, then ordered triples...and you still aren't "really" doing it...
dmckee
+5  A: 

Here you can find diehard test programs and source code for different operating systems. Another nice link could be this one.

schnaader
+3  A: 

With most tests you can supply a large file of random numbers (integer or floating point) and run various tests on that sample file. DIEHARD worked that way, if I remember correctly and some others do, too. If you really want to see your generator fail, you could try using TestU01 by Pierre L'Ecuyer which has enough tests in it to let nearly every generator fail at least one test :-)

Still, for most test suites there is extensive documentation, at least I know this for DIEHARD, the test suite from NIST SP 800-22 as well as DieHarder and TestU01 (links go to the docs). The methods for supplying random numbers to test are usually different but mentioned in the respective documentation.

Joey
+5  A: 

Do you actually need to write your own random number generator? RNGs are notoriously difficult to get right, largely due to the difficulties in testing them.

David Thornley
Most likely this is a school assignment that he needs some help with.
Chris Lively
Unlikely. (a) most schools probably won't use Matlab, (b) PRNGs are something many students not even have a firm grasp of and (c) s?he mentioned some test suites that are beyond normal school stuff.
Joey
And yep, s?he does, see comment on the question itself.
Joey
A: 

The route that I would probably go would be to do a visual analysis of the results. The code for this is simple enough, as shown in the following psudo-code based upon this article.

1. Create an image of size x by y
2. For ndx = 0 to x
  3. For ndy = 0 to y
    4. Let random be a random number between 0 and 1
    5. If random = 1, set the image point at ndx, ndy as black
6. Display the generated image

Also, Random.org has more information on the statistical analysis of algorithms, but they also use the aforementioned article as their example of visual analysis.

Rob
+2  A: 

There are many things to test if you want to test your RNG on your own. Here are a few basic features that may reveal your number sequence to be not truly random or maybe indistinguishable from random?

Take a look at:

  1. The distribution - you have already done some analysis on your distribution. You want each possible number to have the same probability of occurring.

  2. Cyclic behavior - does the same sequence repeat itself over and over again? The repetitive sequence may be quite long.

  3. Occurence of duplicates (...C B B A F F...) , triplets (...C B A A A F...) etc. Statistically in a sequence of random numbers you have a certain probability of dulplicates (the same number generated twice in a row), triplets etc. Calculate this probability and check if your sequence of pseudo random numbers has the same probability of duplicates occurring?

Note that for most of these tests you need to have a quite long sequences of random numbers in order to be able to get sensible and accurate results from statistical analysis.

I assumed peudo random number sequences of integers, which is easily fixed by multiplying your [0, 1] numbers by an appropriate constant.

AnnaR
A: 
brianegge