Package dev.twilite.game.common
Class Random
java.lang.Object
dev.twilite.game.common.Random
Convenience helpers for thread-local random values.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanReturns a random boolean.static doubleReturns a random double from0.0, inclusive, to1.0, exclusive.static doublenextDouble(double min, double max) Returns a random double frommin, inclusive, tomax, exclusive.static doubleReturns a normally distributed value with mean0.0and standard deviation1.0.static doublenextGaussian(double mean, double standardDeviation) Returns a normally distributed value with the supplied mean and standard deviation.static intnextInt()Returns a random integer across the fullintrange.static intnextInt(int max) Returns a random integer from0, inclusive, tomax, exclusive.static intnextInt(int min, int max) Returns a random integer frommin, inclusive, tomax, exclusive.static doublenextLogNormal(double median, double sigma) Returns a log-normally distributed value.static intnextValue(int[] values) Returns a random integer array element.static <T> TnextValue(Collection<T> values) Returns a random collection element, ornullwhen the collection is empty.static <T> TnextValue(T[] elements) Returns a random array element, ornullwhen the array is empty.static <T> TnextValue(T[] elements, T fallback) Returns a random array element, ordefaultValuewhen the array is empty.
-
Constructor Details
-
Random
public Random()
-
-
Method Details
-
nextInt
public static int nextInt()Returns a random integer across the fullintrange. -
nextInt
public static int nextInt(int max) Returns a random integer from0, inclusive, tomax, exclusive. -
nextInt
public static int nextInt(int min, int max) Returns a random integer frommin, inclusive, tomax, exclusive.If the bounds are equal, that value is returned.
-
nextBoolean
public static boolean nextBoolean()Returns a random boolean. -
nextDouble
public static double nextDouble()Returns a random double from0.0, inclusive, to1.0, exclusive. -
nextDouble
public static double nextDouble(double min, double max) Returns a random double frommin, inclusive, tomax, exclusive.If the bounds are equal, that value is returned.
-
nextGaussian
public static double nextGaussian()Returns a normally distributed value with mean0.0and standard deviation1.0. -
nextGaussian
public static double nextGaussian(double mean, double standardDeviation) Returns a normally distributed value with the supplied mean and standard deviation. -
nextLogNormal
public static double nextLogNormal(double median, double sigma) Returns a log-normally distributed value. -
nextValue
public static <T> T nextValue(T[] elements, T fallback) Returns a random array element, ordefaultValuewhen the array is empty. -
nextValue
public static <T> T nextValue(T[] elements) Returns a random array element, ornullwhen the array is empty. -
nextValue
Returns a random collection element, ornullwhen the collection is empty. -
nextValue
public static int nextValue(int[] values) Returns a random integer array element.
-