public class RandomSampling
extends java.lang.Object
| Constructor and Description |
|---|
RandomSampling() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
getRandomElement(java.util.List<T> list)
Samples a random element from the given list with a uniform distribution of probabilities.
|
static <T> T |
getRandomElement(java.util.List<T> list,
T defaultValue)
Samples a random element from the given list with a uniform distribution of probabilities.
|
static java.util.Random |
getThreadRandom()
Retrieves a thread-local random number generator.
|
public static java.util.Random getThreadRandom()
public static <T> T getRandomElement(java.util.List<T> list)
This method is thread safe.
list - - list to sample from.org.apache.commons.lang.NullArgumentException - - if the list is null.java.lang.IndexOutOfBoundsException - - if the list is empty.public static <T> T getRandomElement(java.util.List<T> list,
T defaultValue)
This method is thread safe.
list - - list to sample from.defaultValue - - value to return if the list is empty or null.