Class BallBox

java.lang.Object
  |
  +--BallBox

public class BallBox
extends java.lang.Object

This class implements a random number generator where the numbers in the sequence are guaranteed to be unique.


Constructor Summary
BallBox()
          Creates a ballbox that will return any legal positive integer.
BallBox(int max)
          Creates a ballbox that will return numbers in the sequence 0..max-1.
BallBox(int max, long seed)
          Creates a seeded ballbox that will return numbers in the sequence 0..max-1.
BallBox(long seed)
          Creates a seeded ballbox that will return any legal positive integer.
 
Method Summary
 boolean moreBalls()
          Returns true if there are unused numbers in the sequence.
 int nextBall()
          Returns the next number in the sequence.
 void refill()
          Reset the sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BallBox

public BallBox(int max)
Creates a ballbox that will return numbers in the sequence 0..max-1.

Parameters:
max - the maximum number returned.

BallBox

public BallBox(int max,
               long seed)
Creates a seeded ballbox that will return numbers in the sequence 0..max-1.

Parameters:
max - the maximum number returned.
seed - seed for the random number generator.

BallBox

public BallBox()
Creates a ballbox that will return any legal positive integer.


BallBox

public BallBox(long seed)
Creates a seeded ballbox that will return any legal positive integer.

Parameters:
seed - the seed for the random number generator.
Method Detail

nextBall

public int nextBall()
Returns the next number in the sequence. If all possible values have been used, a -1 will be returned.

Returns:
the next number in the sequence, or -1 if the box is empty.

refill

public void refill()
Reset the sequence.


moreBalls

public boolean moreBalls()
Returns true if there are unused numbers in the sequence.

Returns:
true if there are more balls in the box and false otherwise.