public final class GameRandom
extends java.util.Random
Random
implementation.Modifier and Type | Method and Description |
---|---|
<T> T |
choose(java.util.Collection<T> coll)
Chooses a pseudo-random element from the specified collection.
|
double |
choose(double[] array)
Chooses a pseudo-random element from the specified array.
|
int |
choose(int[] array)
Chooses a pseudo-random element from the specified array.
|
long |
choose(long[] array)
Chooses a pseudo-random element from the specified array.
|
<T> T |
choose(T[] array)
Chooses a pseudo-random element from the specified array.
|
int |
getIndex(double[] indexProbabilities)
Returns a pseudo-random index that is distributed by the weights of the defined probability array.
|
java.awt.geom.Point2D |
getLocation(double x,
double y,
double width,
double height)
Gets a pseudo-random location within the specified boundaries.
|
java.awt.geom.Point2D |
getLocation(java.awt.geom.Ellipse2D circle)
Gets a pseudo-random location in the specified circle.
|
java.awt.geom.Point2D |
getLocation(IEntity entity)
Gets a pseudo-random location within the specified entity boundaries.
|
java.awt.geom.Point2D |
getLocation(IMap map)
Gets a pseudo-random location within the specified map boundaries.
|
java.awt.geom.Point2D |
getLocation(java.awt.geom.Line2D line)
Gets a pseudo-random location on the specified line.
|
java.awt.geom.Point2D |
getLocation(java.awt.geom.Point2D start,
java.awt.geom.Point2D end)
Gets a pseudo-random location on the line connecting the two specified points.
|
java.awt.geom.Point2D |
getLocation(java.awt.geom.Rectangle2D rect)
Gets a pseudo-random location within the specified boundaries.
|
<T extends java.lang.Enum<?>> |
next(java.lang.Class<T> clazz) |
java.lang.String |
nextAlphabetic(int length)
Gets a pseudo-random alphabetic String of the specified length.
|
java.lang.String |
nextAlphabetic(int length,
boolean lowerCase)
Gets a pseudo-random alphabetic String of the specified length.
|
java.lang.String |
nextAlphanumeric(int length)
Gets a pseudo-random alphanumeric String of the specified length.
|
java.lang.String |
nextAlphanumeric(int length,
boolean lowerCase)
Gets a pseudo-random alphanumeric String of the specified length.
|
java.lang.String |
nextAlphanumeric(int length,
boolean digit,
boolean lowerCase)
Gets a pseudo-random alphanumeric String of the specified length.
|
char |
nextAscii()
Gets a pseudo-random char value.
|
java.lang.String |
nextAscii(int length)
Gets a pseudo-random String of the specified length.
|
char |
nextChar()
Gets a pseudo-random char value.
|
char |
nextChar(java.lang.String alphabet)
Gets a pseudo-random char value from the specified alphabet.
|
double |
nextDouble(double bound)
Returns a pseudo-random
double value between zero (inclusive)
and the specified bound (exclusive). |
double |
nextDouble(double min,
double bound)
Returns a pseudo-random
double value between the specified
origin (inclusive) and the specified bound (exclusive). |
float |
nextFloat(float bound)
Returns a pseudo-random
float value between zero (inclusive)
and the specified bound (exclusive). |
float |
nextFloat(float min,
float bound)
Returns a pseudo-random
float value between the specified
origin (inclusive) and the specified bound (exclusive). |
int |
nextInt(int min,
int bound)
Returns a pseudo-random
int value between the specified
origin (inclusive) and the specified bound (exclusive). |
long |
nextLong(long bound)
Returns a pseudo-random
long value between zero (inclusive)
and the specified bound (exclusive). |
long |
nextLong(long min,
long bound)
Returns a pseudo-random
long value between the specified
origin (inclusive) and the specified bound (exclusive). |
int |
nextSign()
Gets a random algebraic sign that can be used to multiply values with it.
|
boolean |
probe(double probability)
Probes a pseudo-random value between 0.0 and 1.0 and checks whether it matches the specified probability.
|
<T> java.util.Collection<T> |
sample(java.util.Collection<T> collection,
int amount,
boolean replacement) |
<T> T[] |
sample(T[] array,
int amount,
boolean replacement) |
void |
setSeed(java.lang.String seed)
Sets the seed of this random number generator using a
String seed. |
void |
shuffle(double[] array)
Shuffles the elements in the specified array.
|
void |
shuffle(int[] array)
Shuffles the elements in the specified array.
|
<T> void |
shuffle(java.util.List<T> coll)
Shuffles the elements in the specified collection.
|
void |
shuffle(long[] array)
Shuffles the elements in the specified array.
|
<T> void |
shuffle(T[] array)
Shuffles the elements in the specified array.
|
double |
shuffleSign(double value)
Shuffles the algebraic sign of the specified double value.
|
float |
shuffleSign(float value)
Shuffles the algebraic sign of the specified float value.
|
int |
shuffleSign(int value)
Shuffles the algebraic sign of the specified int value.
|
long |
shuffleSign(long value)
Shuffles the algebraic sign of the specified long value.
|
public void setSeed(java.lang.String seed)
String
seed.seed
- The initial seed.Random.setSeed(long)
public <T> T[] sample(T[] array, int amount, boolean replacement)
public <T> java.util.Collection<T> sample(java.util.Collection<T> collection, int amount, boolean replacement)
public <T> T choose(T[] array)
T
- The type of the elements in the array.array
- The array to choose from.public int choose(int[] array)
array
- The array to choose from.java.lang.IllegalArgumentException
- When the specified array is null or empty.public long choose(long[] array)
array
- The array to choose from.java.lang.IllegalArgumentException
- When the specified array is null or empty.public double choose(double[] array)
array
- The array to choose from.java.lang.IllegalArgumentException
- When the specified array is null or empty.public <T> T choose(java.util.Collection<T> coll)
T
- The type of the elements in the collection.coll
- The collection to choose from.public <T> void shuffle(T[] array)
T
- The type of the elements in the collection.array
- The array to be shuffled.public void shuffle(int[] array)
array
- The array to be shuffled.public void shuffle(long[] array)
array
- The array to be shuffled.public void shuffle(double[] array)
array
- The array to be shuffled.public <T> void shuffle(java.util.List<T> coll)
T
- The type of the elements in the collection.coll
- The collection to be shuffled.public int nextSign()
This either returns 1 or -1 depending on the random outcome.
public int shuffleSign(int value)
value
- The value to shuffle.nextSign()
public float shuffleSign(float value)
value
- The value to shuffle.nextSign()
public long shuffleSign(long value)
value
- The value to shuffle.nextSign()
public double shuffleSign(double value)
value
- The value to shuffle.nextSign()
public long nextLong(long bound)
long
value between zero (inclusive)
and the specified bound (exclusive).bound
- the upper bound (exclusive). Must be positive.long
value between zero
(inclusive) and the bound (exclusive)java.lang.IllegalArgumentException
- if bound
is not positivepublic long nextLong(long min, long bound)
long
value between the specified
origin (inclusive) and the specified bound (exclusive).min
- the least value returnedbound
- the upper bound (exclusive)long
value between the origin
(inclusive) and the bound (exclusive)java.lang.IllegalArgumentException
- if origin
is greater than bound
public double nextDouble(double bound)
double
value between zero (inclusive)
and the specified bound (exclusive).bound
- the upper bound (exclusive). Must be positive.double
value between zero
(inclusive) and the bound (exclusive)java.lang.IllegalArgumentException
- if bound
is not positivepublic double nextDouble(double min, double bound)
double
value between the specified
origin (inclusive) and the specified bound (exclusive).min
- the least value returnedbound
- the upper bound (exclusive)double
value between the origin
(inclusive) and the bound (exclusive)java.lang.IllegalArgumentException
- if origin
is greater than bound
public float nextFloat(float bound)
float
value between zero (inclusive)
and the specified bound (exclusive).bound
- the upper bound (exclusive). Must be positive.float
value between zero
(inclusive) and the bound (exclusive)java.lang.IllegalArgumentException
- if bound
is not positivepublic float nextFloat(float min, float bound)
float
value between the specified
origin (inclusive) and the specified bound (exclusive).min
- the least value returnedbound
- the upper bound (exclusive)float
value between the origin
(inclusive) and the bound (exclusive)java.lang.IllegalArgumentException
- if origin
is greater than bound
public int nextInt(int min, int bound)
int
value between the specified
origin (inclusive) and the specified bound (exclusive).min
- the least value returnedbound
- the upper bound (exclusive)int
value between the origin
(inclusive) and the bound (exclusive)java.lang.IllegalArgumentException
- if origin
is greater than bound
public <T extends java.lang.Enum<?>> T next(java.lang.Class<T> clazz)
public boolean probe(double probability)
Example: if the specified probability is 0.5, the sampled value needs to be less than or equal to the specified value in order for this method to return true.
probability
- The probability to check.public int getIndex(double[] indexProbabilities)
indexProbabilities
- The index with the probabilities for the related index.public java.awt.geom.Point2D getLocation(double x, double y, double width, double height)
x
- The min-x coordinate of the boundaries.y
- The min-y coordinate of the boundaries.width
- The width of the boundaries.height
- The height of the boundaries.public java.awt.geom.Point2D getLocation(java.awt.geom.Rectangle2D rect)
rect
- The rectangle that defines the boundaries.public java.awt.geom.Point2D getLocation(IEntity entity)
entity
- The entity that defines the boundaries.IEntity.getBoundingBox()
public java.awt.geom.Point2D getLocation(IMap map)
map
- The map that defines the boundaries.IMap.getBounds()
public java.awt.geom.Point2D getLocation(java.awt.geom.Ellipse2D circle)
circle
- The circle that defines the boundaries.public java.awt.geom.Point2D getLocation(java.awt.geom.Line2D line)
line
- The line that defines the boundaries.Line2D.getP1()
,
Line2D.getP2()
public java.awt.geom.Point2D getLocation(java.awt.geom.Point2D start, java.awt.geom.Point2D end)
start
- The start point.end
- The end point.public char nextChar()
public char nextChar(java.lang.String alphabet)
alphabet
- The alphabet to chose the character from.public char nextAscii()
public java.lang.String nextAscii(int length)
Characters will be chosen from the set of characters whose ASCII value is between 32 and 126 (inclusive)
length
- The length of the String.public java.lang.String nextAlphanumeric(int length)
length
- The length of the String.public java.lang.String nextAlphanumeric(int length, boolean lowerCase)
length
- The length of the String.lowerCase
- Indicates whether lower-case letters will be included in the String.public java.lang.String nextAlphanumeric(int length, boolean digit, boolean lowerCase)
length
- The length of the String.digit
- Indicates whether digits will be included in the string.lowerCase
- Indicates whether lower-case letters will be included in the String.public java.lang.String nextAlphabetic(int length)
length
- The length of the String.public java.lang.String nextAlphabetic(int length, boolean lowerCase)
length
- The length of the String.lowerCase
- Indicates whether lower-case letters will be included in the String.