14.1 Pseudorandom Numbers Truly random numbers are unpredictable you cannot determine the exact value of the next number. However, random values can have certain well-known distributions. When random values are uniformly distributed between a minimum and a maximum value (for example, between 0 and 1), every value has an equal probability of occurring. Random values that are normally distributed have probabilities that are represented by the familiar bell curve. A random number generator incorporates an algorithm for generating random values. We typically start each algorithm with a given value, called the seed. The random number generator uses the seed to generate the first random value, and then it uses the first value to generate the second random value, and so on. But if the algorithm is self- enclosed it does not incorporate a "live" value from the outside world, such as the level of some electric noise, the least significant bits of the system clock time, or the measured response time of a person the generator cannot produce unpredictable values. If such an algorithm is given the same seed value each time, it will always generate the same sequence of values, so we try to compensate by making the initial seed value as random as possible. A common trick is to use the current system clock time (or some of its least significant digits) as the seed. However, although the sequence of generated values will be different for each seed value, the algorithm will precisely determine each "random" value based on the previous value in the sequence. Therefore, a random number generator can produce values that only appear to be random. The best algorithms have long periods they generate a long sequence of values before the sequence repeats itself. It is common to call the values cranked out by a computer random number generator pseudorandom numbers. Though not truly random, these values are still very useful. In the rest of this chapter, we'll drop the prefix pseudo when referring to computer-generated random numbers. |
Top |