Here you can find the source of getRandomElement(final List
Parameter | Description |
---|---|
list | the specified list |
public static <T> T getRandomElement(final List<T> list)
//package com.java2s; // BWEM is free software, licensed under the MIT/X11 License. import java.util.List; import java.util.SplittableRandom; public class Main { private static final SplittableRandom randomGenerator = new SplittableRandom(); /**// w w w .ja v a2s . co m * Returns a random element from the specified container. * There is nothing special about this function other than to provide * a function similar to the one provided in the original C++ BWEM. * * @param list the specified list */ public static <T> T getRandomElement(final List<T> list) { final int randomIndex = randomGenerator.nextInt(list.size()); return list.get(randomIndex); } }