edu.kzoo.util
Class RandNumGenerator

java.lang.Object
  |
  +--java.util.Random
        |
        +--edu.kzoo.util.RandNumGenerator
All Implemented Interfaces:
java.io.Serializable

public class RandNumGenerator
extends java.util.Random

Kalamazoo College Utility Classes:
The RandNumGenerator class provides a singleton object for random number generation. RandNumGenerator extends the java.util.Random class, so the object of this class inherits all methods defined for the Random class. Using this class, though, many different objects can share a single source of random numbers. This eliminates the potential problem of having multiple random number generators generating sequences of numbers that are too similar.

Example of how to use RandNumGenerator:


       RandNumGenerator randNumGen = RandNumGenerator.getInstance();
       int anInt = randNumGen.nextInt(4);
       double aDouble = randNumGen.nextDouble();
    

The original RandNumGenerator class, which provided a getInstance method but did not extend Random, was copyright© 2002 College Entrance Examination Board (www.collegeboard.com).

Version:
1 December 2003
Author:
Alyce Brady
See Also:
Serialized Form

Method Summary
static RandNumGenerator getInstance()
          Returns a random number generator.
 boolean nextBoolean()
          Returns a pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
 double nextDouble()
          Returns a pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.
 int nextInt(int n)
          Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
 void setSeed(long seed)
          Sets the seed of this random number generator using a single long seed.
 
Methods inherited from class java.util.Random
next, nextBytes, nextFloat, nextGaussian, nextInt, nextLong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static RandNumGenerator getInstance()
Returns a random number generator. Always returns the same RandNumGenerator object to provide a better sequence of random numbers.


setSeed

public void setSeed(long seed)
Sets the seed of this random number generator using a single long seed. For more technical details, see the class documentation for the Random class.

Overrides:
setSeed in class java.util.Random
Returns:
a pseudorandom, uniformly distributed boolean value from this random number generator's sequence
See Also:
Random.setSeed(long)

nextBoolean

public boolean nextBoolean()
Returns a pseudorandom, uniformly distributed boolean value from this random number generator's sequence. The values true and false are produced with (approximately) equal probability. For more technical details, see the class documentation for the Random class.

Overrides:
nextBoolean in class java.util.Random
Returns:
a pseudorandom, uniformly distributed boolean value from this random number generator's sequence
See Also:
Random.nextBoolean()

nextDouble

public double nextDouble()
Returns a pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence. For more technical details, see the class documentation for the Random class.

Overrides:
nextDouble in class java.util.Random
Returns:
a pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.
See Also:
Random.nextDouble()

nextInt

public int nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. For more technical details, see the class documentation for the Random class.

Overrides:
nextInt in class java.util.Random
Parameters:
n - the bound on the random number to be returned. Must be positive.
Returns:
a pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive).
Throws:
java.lang.IllegalArgumentException - n is not positive
See Also:
Random.nextInt(int)