Java List Random Item chooseRandomElement(List list, Random random)

Here you can find the source of chooseRandomElement(List list, Random random)

Description

choose Random Element

License

Open Source License

Declaration

static public <Type> Type chooseRandomElement(List<Type> list, Random random) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.List;
import java.util.Random;

public class Main {
    static public <Type> Type chooseRandomElement(List<Type> list, Random random) {
        final int index = random.nextInt(list.size());
        return list.get(index);
    }// w w  w.  j ava 2  s . c om
}

Related

  1. asRandomAccessList(Collection list)
  2. choice(List list)
  3. choice(T... list)
  4. choose(Random random, List list)
  5. chooseRandom(List list)
  6. computeCrossProduct(List> allArgPossibilities, int maximumSize)
  7. findFirst(List list, T value, Comparator comparator)
  8. generateInteger(int min, int maxInclusive, List excludedValues)
  9. getRandomElement(final List list)