AP® Computer Science Marine Biology Simulation

Class RandNumGenerator

java.lang.Object
  |
  +--RandNumGenerator

public class RandNumGenerator
extends java.lang.Object

AP® Computer Science Marine Biology Simulation:
The RandNumGenerator class provides a singleton java.util.Random object for random number generation. Using this class, 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:


       import java.util.Random;

       Random randNumGen = RandNumGenerator.getInstance();
       int randomNum = randNumGen.nextInt(4);
       double randomDouble = randNumGen.nextDouble();
    

The RandNumGenerator class is copyright© 2002 College Entrance Examination Board (www.collegeboard.com).

Version:
1 July 2002
See Also:
Random

Constructor Summary
RandNumGenerator()
           
 
Method Summary
static java.util.Random getInstance()
          Returns a random number generator.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandNumGenerator

public RandNumGenerator()
Method Detail

getInstance

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

AP® Computer Science Marine Biology Simulation

Copyright© 2002 College Entrance Examination Board