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.
-
-
Constructor Summary
Constructors Constructor Description RandomGenerator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanchance(float n)Produces a random float between 0.0 and 1.0, then compares that number againstnand returns the result.floatgetFloat(float min, float max)Returns a random float somewhere in the range between the minimum (inclusive) and maximum (exclusive).intgetInt(int min, int max)Returns a random integer somewhere in the range between the minimum (inclusive) and maximum (exclusive).<T> Tpick(java.util.List<T> elements)Picks and returns a random element from the specified list.
-
-
-
Method Detail
-
getInt
public int getInt(int min, int max)Returns a random integer somewhere in the range between the minimum (inclusive) and maximum (exclusive).
-
getFloat
public float getFloat(float min, float max)Returns a random float somewhere in the range between the minimum (inclusive) and maximum (exclusive).
-
chance
public 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 <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.
-
-