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
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.
Here you can find diehard test programs and source code for different operating systems. Another nice link could be this one.
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.
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.
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.
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:
The distribution - you have already done some analysis on your distribution. You want each possible number to have the same probability of occurring.
Cyclic behavior - does the same sequence repeat itself over and over again? The repetitive sequence may be quite long.
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.