Java List Random Item chooseRandom(List list)

Here you can find the source of chooseRandom(List list)

Description

choose Random

License

Open Source License

Declaration

public static <T> T chooseRandom(List<T> list) 

Method Source Code

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

import java.util.List;

import java.util.Random;

public class Main {
    private static final Random seed = new Random();

    public static <T> T chooseRandom(List<T> list) {
        return list.get(random(0, list.size() - 1));
    }/*from   w w w .j  a v  a2  s .co m*/

    public static int random(int min, int max) {
        return seed.nextInt(max - min + 1) + min;
    }
}

Related

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