public final class RandomUtils extends Object
Modifier and Type | Method and Description |
---|---|
static int |
intFromRange(int low,
int high)
Selects an integer at random, bounded by the specified range of
low (inclusive) to high (exclusive).
|
static <T> T |
select(List<T> choices)
Randomly selects and returns one item from the given list.
|
public static <T> T select(List<T> choices)
T
- the item typechoices
- the list of choicesNullPointerException
- if the parameter is nullIllegalArgumentException
- if the parameter is an empty listpublic static int intFromRange(int low, int high)
low
must be greater or
equal to zero; high
must be greater than low
.
For example, invoking the following:
int r = RandomUtils.intFromRange(5, 10);will randomly return one of
5, 6, 7, 8, 9
.low
- the lowest value (inclusive)high
- the highest value (exclusive)IllegalArgumentException
- if low < 0 or high <= lowCopyright © 2015. All Rights Reserved.