java.lang.Object
provided.utils.valueGenerator.impl.Randomizer
- All Implemented Interfaces:
IRandomizer
Concrete implementation of IRandomizer
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor for use by the Singleton only.. -
Method Summary
Modifier and TypeMethodDescriptionrandomBounds(Rectangle rect, Dimension maxDim)
Generates a randomly located and sized rectanglerandomChoice(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).Generates a random colorReturns a random square Dimension, whose width is maxDim.width/2<=width<=maxDim.widthdouble
randomDouble(double min, double max)
Returns a random double greater than or equal to min and less than max.int
randomInt(int min, int max)
Returns a random integer greater than or equal to min and less than or equal to max.Generates a random location point subject to the constraint that 0<=X<=dim.width and 0<=Y<=dim.height.Generates a random location point subject to the constraint that rect.x<=X<=rect.x+rect.width and rect.y<=Y<=rect.y+rect.height.Returns a random velocity (as a Point) subject to the constraint that the absolute value of the velocity (speed) within the bound (inclusive) defined by rect.
-
Field Details
-
Singleton
Singleton instance of this class
-
-
Constructor Details
-
Randomizer
private Randomizer()Private constructor for use by the Singleton only..
-
-
Method Details
-
randomLoc
Description copied from interface:IRandomizer
Generates a random location point subject to the constraint that rect.x<=X<=rect.x+rect.width and rect.y<=Y<=rect.y+rect.height. Note that the definition of a Rectangle object requires that (x,y) be defined as the upper left corner and that width and height must both be non-negative.- Specified by:
randomLoc
in interfaceIRandomizer
- Parameters:
rect
- The bounds for the x and y values of the created Point- Returns:
- A Point object whose x and y are subject to the given bounds
-
randomLoc
Description copied from interface:IRandomizer
Generates a random location point subject to the constraint that 0<=X<=dim.width and 0<=Y<=dim.height.- Specified by:
randomLoc
in interfaceIRandomizer
- Parameters:
dim
- The bounds for the x and y values of the created Point- Returns:
- A Point object whose x and y are subject to the given bounds
-
randomInt
public int randomInt(int min, int max)Description copied from interface:IRandomizer
Returns a random integer greater than or equal to min and less than or equal to max.- Specified by:
randomInt
in interfaceIRandomizer
- Parameters:
min
- The minimum allowed valuemax
- The maximum allowed value- Returns:
- an int subject to the given bounds
-
randomDouble
public double randomDouble(double min, double max)Description copied from interface:IRandomizer
Returns a random double greater than or equal to min and less than max.- Specified by:
randomDouble
in interfaceIRandomizer
- Parameters:
min
- The minimum allowed valuemax
- The maximum allowed value- Returns:
- a double subject to the given bounds
-
randomVel
Description copied from interface:IRandomizer
Returns a random velocity (as a Point) subject to the constraint that the absolute value of the velocity (speed) within the bound (inclusive) defined by rect. Thus the resultant velocity may be negative. The given Rectangle should use all positive values. To create velocities or any Point with asymmetrical bounds, use the randomLoc(Rectangle rect) method with the input rectangle set to the desired bounds.- Specified by:
randomVel
in interfaceIRandomizer
- Parameters:
rect
- The bounds for the absolute value of the velocity in the x and y directions.- Returns:
- a Point object with x and y subject to the given bounds.
-
randomDim
Description copied from interface:IRandomizer
Returns a random square Dimension, whose width is maxDim.width/2<=width<=maxDim.width- Specified by:
randomDim
in interfaceIRandomizer
- Parameters:
maxDim
- The bounds on the side of the created Dimension.- Returns:
- A random square Dimension subject to the given bound
-
randomBounds
Description copied from interface:IRandomizer
Generates a randomly located and sized rectangle- Specified by:
randomBounds
in interfaceIRandomizer
- Parameters:
rect
- The bounds for the location of the created rectanglemaxDim
- The bounds for the dimensions of the create rectangle- Returns:
- A Rectangle with location and dimensions subject to the given bounds.
-
randomColor
Description copied from interface:IRandomizer
Generates a random color- Specified by:
randomColor
in interfaceIRandomizer
- Returns:
- a random Color object
-
randomChoice
Description copied from interface:IRandomizer
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 interfaceIRandomizer
- Parameters:
x
- The first of two choicesy
- The second of two choicesprobX
- The probability of the first choice- Returns:
- Either x or y as per the probability of choosing them.
-