Java Utililty Methods List Random Item

List of utility methods to do List Random Item

Description

The list of methods to do List Random Item are organized into topic(s).

Method

ListasRandomAccessList(Collection list)
Returns a list implementation that allows for efficient random access.
if (list instanceof List<?> && list instanceof RandomAccess) {
    return (List<T>) list;
return new ArrayList<T>(list);
Tchoice(List list)
Returns a random element a list.
return list.get(GENERATOR.nextInt(list.size()));
Tchoice(T... list)
choice
return choice(asList(list));
Tchoose(Random random, List list)
choose
if (random == null)
    return list.get(0);
return list.get(random.nextInt(list.size()));
TchooseRandom(List list)
choose Random
return list.get(random(0, list.size() - 1));
TypechooseRandomElement(List list, Random random)
choose Random Element
final int index = random.nextInt(list.size());
return list.get(index);
List>computeCrossProduct(List> allArgPossibilities, int maximumSize)
Create the cross product of a list of list.
if (maximumSize < 1) {
    return null;
double Q = -1.0;
if (maximumSize < Integer.MAX_VALUE) {
    int size = 1;
    int counter = 0;
    for (Collection<E> possibilities : allArgPossibilities) {
...
intfindFirst(List list, T value, Comparator comparator)
Finds the first index where the value is located or the index where it could be inserted, similar to the regular binarySearch() methods, but it works with duplicate elements.
return findFirst(list, 0, list.size(), value, comparator);
IntegergenerateInteger(int min, int maxInclusive, List excludedValues)
generate Integer
int random = generateInteger(min, maxInclusive);
boolean found = false;
for (Integer val : excludedValues) {
    if (val == random) {
        found = true;
if (found) {
...
TgetRandomElement(final List list)
Returns a random element from the specified container.
final int randomIndex = randomGenerator.nextInt(list.size());
return list.get(randomIndex);