/**
 * Pseudo-random number generator.  Based on the code on page 108 of
 * L.C. Paulson.
 * ML for the Working Programmer.
 * Cambridge University Press.
 * 1996.
 *
 * @version     1.1    July 5, 2000
 * @author      Franck van Breugel
 */
public class PseudoRandomNumberGenerator 
{
    /** Constant used to compute the next pseudo-random number. */
    private static final double CONST = 16807.0;

    /** Maximal pseudo-random number produced + 1.0 */
    private static final double MAX = 2147483647.0;

    /**
     * Returns a pseudo-random number between 0.0 and MAX - 1.0.
     * @param seed The seed used to compute the next pseudo-random number.
     * @return A pseudo-random number between 0.0 and MAX - 1.0.
     */
    public static double random(double seed) 
    {
        double d = CONST * seed;
        return (d - MAX * Math.floor(d / MAX));
    }

    /** Number of pseudo-random numbers to be printed. */
    private static final int NUM = 100;

    /** Prints NUM pseudo-random numbers. */
    public static void main(String[] args) 
    {
        double seed = 1.0; // could something like the current time instead of 1.0
        for(int i = 0; i < NUM; i++) 
        {
            seed = random(seed);
            System.out.println(seed);
        }
    }
}
