Here you can find the source of randomElement(List extends T> list, Random random)
public static <T> T randomElement(List<? extends T> list, Random random)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static <T> T randomElement(List<? extends T> list, Random random) { if (list.isEmpty()) throw new IndexOutOfBoundsException("List is empty"); return list.get(random.nextInt(list.size())); }/*from w w w .j a v a2 s . com*/ }