Here you can find the source of random(Collection
public static <T> T random(Collection<T> coll)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Random; public class Main { public static <T> T random(Collection<T> coll) { int num = (new Random().nextInt(coll.size())); for (T t : coll) { if (--num < 0) { return t; }// ww w .ja v a 2 s .c o m } return null; } }