Here you can find the source of pickOneAtRandom(List
public static <T> T pickOneAtRandom(List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.List; import java.util.Random; public class Main { private static final Random RANDOM = new Random(); public static <T> T pickOneAtRandom(List<T> list) { return pickOneAtRandom(list, RANDOM); }/*from w w w .j a va2 s. c om*/ public static <T> T pickOneAtRandom(List<T> list, Random random) { if (list.size() == 1) { return list.get(0); } else if (list.size() == 0) { throw new IllegalArgumentException("List must have at least one element"); } else { int index = random.nextInt(list.size()); return list.get(index); } } }