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 Random random = new Random(System.nanoTime()); public static <T> T random(Collection<T> coll) { if (coll.size() == 0) return null; int num = (int) (Math.random() * coll.size()); for (T t : coll) if (--num < 0) return t; throw new AssertionError(); }// w w w. j ava2s .c o m public static int random(int min, int max) { return min + (int) (Math.random() * (max - min + 1)); } }