Here you can find the source of randomEle(List
public static <T> T randomEle(List<T> list)
//package com.java2s; //License from project: Apache License import java.util.List; import java.util.Random; public class Main { private static Random random = new Random(); public static <T> T randomEle(List<T> list) { return randomEle(list, list.size()); }//from w w w . j a va 2s.c o m public static <T> T randomEle(List<T> list, int limit) { return list.get(randomInt(limit)); } public static int randomInt(int min, int max) { return random.nextInt(max - min) + min; } public static int randomInt() { return random.nextInt(); } public static int randomInt(int limit) { return random.nextInt(limit); } }