## How Computers Generate Random Numbers - Chapter 9

Chapter 8                     Chapter 10

### 9.0    HOW GOOD A RANDOM GENERATOR DO YOU NEED?

The exact determination of whether a particular random number generator will be adequate for your needs is highly dependent upon your application. There is a trade off between resolution and quantity. At high resolution, it doesn't take very many random numbers before some non-randomness can be detected. At low resolution, it takes quite a large number of random numbers before some non-randomness can be detected.

The chi-square tests above give us an idea of where the tradeoff lies. Each test used an expected value of 10 balls per bin, and each ball required DIM random numbers per ball, where DIM is the dimension of the chi-square test being performed. The number of bins per dimension determined the resolution required of the random numbers.

For example, the MTH\$RANDOM number generator generates floating point deviates between 0 and 1. The floating point number returned is an F_floating datum type with 24 bits of accuracy. If we are doing a 1-D chi-square test with 128 bins, we would convert the floating point random number into an integer between 0 and 127 and then add 1. This represents a loss of 17 bits of resolution, since we essentially truncate the low 17 bits of the F_floating datum and keep the upper 7 bits which represents a number between 0 and 127. Because of this loss of resolution, we can generate a lot more random numbers before any non-randomness can be detected.

The tests above on the linear congruential generators without shuffling were able to detect non-randomness in the generators after about one million values were generated. This value is somewhat approximate, but it gives you an idea of the order of magnitude above which you cannot expect the sequence to appear random. If you only need a small number of random numbers, say less than 100,000, if you do not demand high resolution of the numbers, and if you're not concerned about correlations between the initial SEED value and the first few numbers from the generator, or about occasional correlations between successive runs of the generator, or about the numbers all lying in parallel lines and parallel planes, then the simple MTH\$RANDOM or ANSI C random number generators may be adequate for your needs. Despite it's numerous drawbacks, this simple method of random number generation is quite adequate for many applications.

If you are concerned about the quality of your random numbers, or if you need more than 100,000 random numbers, or if you want to make sure there is no easy relation between the initial SEED value and the first few numbers output from the generator, or if you want to make sure there will be no relation between successive runs of the generator, then you can shuffle the numbers using the technique in section 8 (Shuffling). This produces excellent results, the amount of memory required is quite small, and the small extra amount of time required is usually quite trivial.

By shuffling the numbers you may be able to get a million or more satisfactory random numbers from the MTH\$RANDOM or ANSI C random number generators. If significantly more than a million random numbers are needed, then a closer look at your application is warranted to determine if the random number generator will be adequate for the purpose. But don't despair. Just because 50 million shuffled random numbers from the ANSI C generator would fail all of the chi-square tests doesn't mean they won't be quite adequate for you application.

Chapter 8                     Chapter 10