util
Class Randomizer

java.lang.Object
  extended by util.Randomizer
All Implemented Interfaces:
IRandomizer

public class Randomizer
extends Object
implements IRandomizer

Utility class that supplies class routines for generating various random values


Field Summary
static Randomizer Singleton
           
 
Constructor Summary
private Randomizer()
           
 
Method Summary
 Rectangle randomBounds(Rectangle rect, Dimension maxDim)
          Generates a randomly located and sized rectangle
 Object randomChoice(Object x, Object y, double probX)
          Returns a random choice of one of two objects, x and y, where probX is the probability that x will be picked (0<=x<=1).
 Color randomColor()
          Generates a random color
 Dimension randomDim(Dimension maxDim)
          Returns a random square Dimension, whose width is maxDim.width/2<=width<=maxDim.width
 double randomDouble(double min, double max)
          Returns a random double greater than or equal to min and less than or equal to max.
 int randomInt(int min, int max)
          Returns a random integer greater than or equal to min and less than or equal to max.
 Point randomLoc(Dimension dim)
          Generates a random location point subject to the constraint that 0<=X<=maxX and 0<=Y<=maxY.
 Point randomLoc(Rectangle rect)
          Generates a random location point subject to the constraint that 0<=X<=maxX and 0<=Y<=maxY.
 Point randomVel(Rectangle rect)
          Returns a random velocity (as a Point) subject to the constraint that the absolute value of the vleocity (speed) is less than maxV.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Singleton

public static Randomizer Singleton
Constructor Detail

Randomizer

private Randomizer()
Method Detail

randomLoc

public Point randomLoc(Rectangle rect)
Generates a random location point subject to the constraint that 0<=X<=maxX and 0<=Y<=maxY.

Specified by:
randomLoc in interface IRandomizer

randomLoc

public Point randomLoc(Dimension dim)
Generates a random location point subject to the constraint that 0<=X<=maxX and 0<=Y<=maxY.

Specified by:
randomLoc in interface IRandomizer

randomInt

public int randomInt(int min,
                     int max)
Returns a random integer greater than or equal to min and less than or equal to max.

Specified by:
randomInt in interface IRandomizer

randomDouble

public double randomDouble(double min,
                           double max)
Returns a random double greater than or equal to min and less than or equal to max.

Specified by:
randomDouble in interface IRandomizer

randomVel

public Point randomVel(Rectangle rect)
Returns a random velocity (as a Point) subject to the constraint that the absolute value of the vleocity (speed) is less than maxV.

Specified by:
randomVel in interface IRandomizer

randomDim

public Dimension randomDim(Dimension maxDim)
Returns a random square Dimension, whose width is maxDim.width/2<=width<=maxDim.width

Specified by:
randomDim in interface IRandomizer

randomBounds

public Rectangle randomBounds(Rectangle rect,
                              Dimension maxDim)
Generates a randomly located and sized rectangle

Specified by:
randomBounds in interface IRandomizer

randomColor

public Color randomColor()
Generates a random color

Specified by:
randomColor in interface IRandomizer

randomChoice

public Object randomChoice(Object x,
                           Object y,
                           double probX)
Returns a random choice of one of two objects, x and y, where probX is the probability that x will be picked (0<=x<=1).

Specified by:
randomChoice in interface IRandomizer