public final class Rand
extends java.lang.Object
Random internally, but adds a number of convenience
methods on top of it.| Modifier and Type | Method and Description |
|---|---|
static boolean |
chance(float f)
Generates a random number and compares it to a threshold value.
|
static boolean |
nextBoolean() |
static float |
nextFloat()
Returns a random float between 0 (inclusive) and 1 (exclusive).
|
static float |
nextFloat(float lower,
float upper)
Returns a random float between
lower (inclusive) and
upper (exclusive). |
static int |
nextInt(int upper)
Returns an integer between 0 and
upper (exclusive). |
static int |
nextInt(int lower,
int upper)
Returns a random integer between
lower (inclusive) and
upper (exclusive). |
static <E> E |
oneFrom(E[] elements)
Returns a random element from an array.
|
static <E> E |
oneFrom(java.util.List<E> elements)
Returns a random element from a list.
|
public static int nextInt(int upper)
upper (exclusive).public static int nextInt(int lower,
int upper)
lower (inclusive) and
upper (exclusive).public static float nextFloat()
public static float nextFloat(float lower,
float upper)
lower (inclusive) and
upper (exclusive).public static boolean nextBoolean()
public static boolean chance(float f)
java.lang.IllegalArgumentException - if f is outside the range 0..1.public static <E> E oneFrom(java.util.List<E> elements)
java.lang.IllegalArgumentException - if the list is empty.public static <E> E oneFrom(E[] elements)
java.lang.IllegalArgumentException - if the array is empty.