public class Randomizer extends java.lang.Object implements IRandomizer
Modifier and Type | Field and Description |
---|---|
static Randomizer |
Singleton
Singleton design pattern
|
Modifier | Constructor and Description |
---|---|
private |
Randomizer()
Private constructor for Singleton
|
Modifier and Type | Method and Description |
---|---|
java.awt.Rectangle |
randomBounds(java.awt.Rectangle rect,
java.awt.Dimension maxDim)
Generates a randomly located and sized rectangle
|
java.lang.Object |
randomChoice(java.lang.Object x,
java.lang.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).
|
<T> T |
randomChoiceList(T... choices)
Return one of the vararg input parameters with equal probability.
|
java.awt.Color |
randomColor()
Generates a random color
|
java.awt.Dimension |
randomDim(java.awt.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.
|
java.awt.Point |
randomLoc(java.awt.Dimension dim)
Generates a random location point subject to the constraint that 0<=X<=maxX and 0<=Y<=maxY.
|
java.awt.Point |
randomLoc(java.awt.Rectangle rect)
Generates a random location point subject to the constraint that 0<=X<=maxX and 0<=Y<=maxY.
|
java.awt.Point |
randomVel(java.awt.Rectangle rect)
Returns a random velocity (as a Point) subject to the constraint that the absolute value of the velocity (speed) is less than maxV.
|
public static Randomizer Singleton
public java.awt.Point randomLoc(java.awt.Rectangle rect)
randomLoc
in interface IRandomizer
rect
- the bounds for the locationpublic java.awt.Point randomLoc(java.awt.Dimension dim)
randomLoc
in interface IRandomizer
dim
- the bounds for the locationpublic int randomInt(int min, int max)
randomInt
in interface IRandomizer
min
- the min valuemax
- the max valepublic double randomDouble(double min, double max)
randomDouble
in interface IRandomizer
min
- the min valuemax
- the max valepublic java.awt.Point randomVel(java.awt.Rectangle rect)
randomVel
in interface IRandomizer
rect
- the bounds for the velocitypublic java.awt.Dimension randomDim(java.awt.Dimension maxDim)
randomDim
in interface IRandomizer
maxDim
- The bounds for the dimensionpublic java.awt.Rectangle randomBounds(java.awt.Rectangle rect, java.awt.Dimension maxDim)
randomBounds
in interface IRandomizer
rect
- The bounds for the location of the rectanglemaxDim
- The bounds for the size of the rectanglepublic java.awt.Color randomColor()
randomColor
in interface IRandomizer
public java.lang.Object randomChoice(java.lang.Object x, java.lang.Object y, double probX)
randomChoice
in interface IRandomizer
x
- The first object to choose fromy
- The second object to choose fromprobX
- The probability of choosing the first objectpublic <T> T randomChoiceList(T... choices)
randomChoiceList
in interface IRandomizer
T
- The type of the input parameters and thus the return typechoices
- vararg list of choices