Package nl.colorize.multimedialib.math
Class RandomGenerator
- java.lang.Object
-
- nl.colorize.multimedialib.math.RandomGenerator
-
public class RandomGenerator extends java.lang.ObjectUtility class to help with random numbers. This class should be used instead ofMath.random()and similar methods, as using class allows for "fake" random numbers that ensure deterministic behavior.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanchance(float n)Produces a random float between 0.0 and 1.0, then compares that number againstnand returns the result.static floatgetFloat(float min, float max)Returns a random float somewhere in the range between the minimum (inclusive) and maximum (exclusive).static intgetInt(int min, int max)Returns a random integer somewhere in the range between the minimum (inclusive) and maximum (exclusive).static <T> Tpick(java.util.List<T> elements)Picks and returns a random element from the specified list.
-
-
-
Method Detail
-
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 againstnand returns the result. In other words, passing a value of 0.9 against this method will have a 90% chance of returning true.
-
pick
public static <T> T pick(java.util.List<T> elements)
Picks and returns a random element from the specified list.- Throws:
java.lang.IllegalArgumentException- if the provided list is empty.
-
-