public class RandomUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
RandomUtil.Sample<T>
A sample of n elements.
|
Constructor and Description |
---|
RandomUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.ArrayList<T> |
getSample(java.lang.Iterable<T> from,
int size) |
static void |
main(java.lang.String[] args) |
static <K,V> java.util.Map.Entry<K,V> |
randomEntry(java.util.Map<K,V> map)
return a random entry in a map
|
static <T> T |
randomFromIterator(java.util.Iterator<T> iter) |
static int |
randomInt(int fromInclusive,
int toExclusive)
generates a random int in the range [fromInclusive-toExclusive)
|
static <T> T |
randomMember(java.util.Collection<T> col)
return a random entry in a collection
|
static <T> T |
removeRandom(java.util.Collection<T> col)
remove and return a random member of the passed Collection
|
static <T> T |
removeRandomFast(java.util.ArrayList<T> list,
java.util.Random rand) |
static int[] |
toShuffledIntArray(java.util.Collection<java.lang.Integer> c,
java.util.Random rand) |
public static int randomInt(int fromInclusive, int toExclusive)
fromInclusive
- toExclusive
- public static <T> T randomMember(java.util.Collection<T> col)
col
- public static <T> T removeRandom(java.util.Collection<T> col)
col
- public static <K,V> java.util.Map.Entry<K,V> randomEntry(java.util.Map<K,V> map)
map
- public static <T> T randomFromIterator(java.util.Iterator<T> iter)
public static <T> T removeRandomFast(java.util.ArrayList<T> list, java.util.Random rand)
public static <T> java.util.ArrayList<T> getSample(java.lang.Iterable<T> from, int size)
public static int[] toShuffledIntArray(java.util.Collection<java.lang.Integer> c, java.util.Random rand)
public static void main(java.lang.String[] args)