|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--cardgame.RandomIntGenerator
The RandomIntGenerator class provides a way to generate random integers within a specific range. It also takes care of reseeding the random number generator after the sequence has been in use for a long time. The default minimum and maximum values have been optimized for use with card games.
Originally appeared in Java Pro, August 2000, page 68.
| Field Summary | |
static int |
DEFAULT_MAXIMUM_RANGE
The public variable DEFAULT_MAXIMUM_RANGE defines the largest integer that will be generated when the no-argument constructor is used. |
static int |
DEFAULT_MINIMUM_RANGE
The public variable DEFAULT_MINIMUM_RANGE defines the smallest integer that will be generated when the no-argument constructor is used. |
private int |
maximumRange
The private variable maximumRange defines the largest integer that will be generated and is set by the setRange method. |
private int |
minimumRange
The private variable minimumRange defines the smallest integer that will be generated and is set by the setRange method. |
private long |
numberOfCalls
The private variable numberOfCalls keeps track of the number of integers that have been generated. |
private java.util.Random |
random
The private variable random is a Java Random class object. |
private int |
range
The private variable range defines the number of integers that will be generated and is calculated in the setRange method. |
| Constructor Summary | |
RandomIntGenerator()
The no-argument constructor creates random numbers within the default limits by supplying the defaults to the two-argument constructor. |
|
RandomIntGenerator(int minRange,
int maxRange)
This constructor creates random numbers within user-specified limits. |
|
| Method Summary | |
int |
nextRandomInt()
The public method nextRandomInt is used to generate and return the next random integer. |
private void |
setRange(int minRange,
int maxRange)
The private method setRange is used by the constructors to set the minimum and maximum range. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
public static final int DEFAULT_MINIMUM_RANGE
RandomIntGenerator(),
DEFAULT_MAXIMUM_RANGEpublic static final int DEFAULT_MAXIMUM_RANGE
RandomIntGenerator(),
DEFAULT_MINIMUM_RANGEprivate int minimumRange
maximumRange,
setRange(int minRange, int maxRange)private int maximumRange
minimumRange,
setRange(int minRange, int maxRange)private int range
setRange(int minRange, int maxRange)private long numberOfCalls
RandomIntGenerator(),
RandomIntGenerator(int minRange, int maxRange),
nextRandomInt()private java.util.Random random
nextRandomInt()| Constructor Detail |
public RandomIntGenerator()
DEFAULT_MINIMUM_RANGE,
DEFAULT_MAXIMUM_RANGE,
RandomIntGenerator(int minRange, int maxRange)
public RandomIntGenerator(int minRange,
int maxRange)
minRange - the smallest number to be generated as an int.maxRange - the largest number to be generated as an int.minimumRange,
maximumRange,
setRange(int minRange, int maxRange),
random,
numberOfCalls| Method Detail |
private void setRange(int minRange,
int maxRange)
minRange - the smallest number to be generated as an int.maxRange - the largest number to be generated as an int.minimumRange,
maximumRange,
rangepublic int nextRandomInt()
random,
numberOfCalls
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||