Java tutorial
//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; } } return null; } }