Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Random; public class Main { public static <E> E randomElement(Collection<E> elements) { return (E) elements.toArray()[randomIndex(elements)]; } public static int randomIndex(Collection<?> collection) { return new Random().nextInt(collection.size()); } }