Class RandomUtil
- java.lang.Object
-
- net.automatalib.common.util.random.RandomUtil
-
public final class RandomUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> @Nullable T
choose(Random rand, List<? extends T> list)
static <T> @Nullable T
choose(Random rand, T[] array)
static int[]
distinctIntegers(Random rand, int num, int max)
static int[]
distinctIntegers(Random rand, int num, int min, int max)
Sample a specified number of distinct integers from a specified range.static <T> List<T>
sample(Random rand, List<? extends T> list, int num)
static <T> List<T>
sampleUnique(Random rand, List<? extends T> list, int num)
Sample a specified number of elements from specified list.
-
-
-
Method Detail
-
distinctIntegers
public static int[] distinctIntegers(Random rand, int num, int min, int max)
Sample a specified number of distinct integers from a specified range.The implementation is based on Floyd's Algorithm F2. Note that this algorithm ensures equal probability of each integer within in the specified range to appear in the returned array but no equal probability of their order.
- Parameters:
rand
- the random instance for generating numbersnum
- number of integers to samplemin
- lower bound (inclusive) of sampled valuesmax
- upper bound (exclusive) of samples values- Returns:
- an array of distinct integers sampled from the specified range
-
distinctIntegers
public static int[] distinctIntegers(Random rand, int num, int max)
-
sampleUnique
public static <T> List<T> sampleUnique(Random rand, List<? extends T> list, int num)
Sample a specified number of elements from specified list.The implementation is based on Floyd's Algorithm F2. Note that this algorithm ensures equal probability of each element within in the specified list to appear in the returned list but no equal probability of their order.
- Parameters:
rand
- the random instance for generating numberslist
- the list to sample elements fromnum
- number of integers to sample- Returns:
- a list of distinct elements sampled from the specified list
-
-