We now describe the implementation of a random number generator based on Equation . Program defines the RandomNumberGenerator class. This class has only static members . Because there can only be one instance of a static data member, the implementation of the RandomNumberGenerator class follows the singleton design pattern.
Program: RandomNumberGenerator Class Definition
Program gives the implementation of the RandomNumberGenerator class. The SetSeed function is used to specify the initial seed, . The seed must fall between 0 and m-1. If it does not, an exception is thrown.
Program: RandomNumberGenerator ClassSetSeed and Next Member Function Definitions
The Next function generates the elements of the random sequence. Each subsequent call returns the next element of the sequence. The implementation follows directly from Equation . Notice that the return value is normalized. Therefore, the values computed by the Next function are uniformly distributed on the interval (0,1).