Package nl.colorize.multimedialib.math
Class RandomGenerator
java.lang.Object
nl.colorize.multimedialib.math.RandomGenerator
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
chance
(float n) Produces a random float between 0.0 and 1.0, then compares that number againstn
and returns the result.static float
getFloat
(float min, float max) Returns a random float somewhere in the range between the minimum (inclusive) and maximum (exclusive).static int
getInt
(int min, int max) Returns a random integer somewhere in the range between the minimum (inclusive) and maximum (exclusive).static <T> T
Picks and returns a random element from the specified iterator.static <T> T
Picks and returns a random element from the specified list.static <T> T
Picks a random key from the specified map.static <T> T
Picks and returns a random element from the specified set.static <T> T
Picks and returns a random element from the specified stream.static Point2D
Picks a random point somewhere within the specified rectangle.static void
Changes the random number generator used by this class to generate "true" random numbers.static void
seed
(long value) Changes the random number generator used by this class to generate deterministic pseudo-random numbers based on the specified seed value.static <T> List
<T> Returns a new list that contains the same elements as the original, but with all elements shuffled to be in random order.
-
Method Details
-
seed
public static void seed(long value) Changes the random number generator used by this class to generate deterministic pseudo-random numbers based on the specified seed value. -
randomSeed
public static void randomSeed()Changes the random number generator used by this class to generate "true" random numbers. This method can be used to revert the changes made by usingseed(long)
. -
getInt
public static int getInt(int min, int max) Returns a random integer somewhere in the range between the minimum (inclusive) and maximum (exclusive). -
getFloat
public static float getFloat(float min, float max) Returns a random float somewhere in the range between the minimum (inclusive) and maximum (exclusive). -
chance
public static boolean chance(float n) Produces a random float between 0.0 and 1.0, then compares that number againstn
and returns the result. In other words, passing a value of 0.9 against this method will have a 90% chance of returning true. -
pick
Picks and returns a random element from the specified list.- Throws:
IllegalArgumentException
- if the provided list is empty.
-
pick
Picks and returns a random element from the specified set.- Throws:
IllegalArgumentException
- if the provided set is empty.
-
pick
Picks and returns a random element from the specified iterator.- Throws:
IllegalArgumentException
- if the provided iterator is empty.
-
pick
Picks and returns a random element from the specified stream.- Throws:
IllegalArgumentException
- if the provided stream is empty.
-
pick
Picks a random key from the specified map. The chance that one of the elements will be chosen is indicated by the values in the map. So if two keys have the same value, the chance that they will be picked is equally likely. A value of 0 indicates the value will never be chosen.- Throws:
IllegalArgumentException
- if the provided map is empty.
-
shuffle
Returns a new list that contains the same elements as the original, but with all elements shuffled to be in random order. This method is similar toCollections.shuffle(List)
, but creates a new list instead of trying to modify the original one. -
pickPoint
Picks a random point somewhere within the specified rectangle.
-