/**
 * 
 */
package com.github.phantomthief.failover.util;

import static java.lang.Math.min;
import static java.util.Collections.emptyList;
import static java.util.Collections.shuffle;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author w.vela
 */
public class RandomListUtils {

    private static final Random RANDOM = new Random();

    private RandomListUtils() {
        throw new UnsupportedOperationException();
    }

    public static <T> T getRandom(List<T> source) {
        if (source == null || source.isEmpty()) {
            return null;
        }
        return source.get(RANDOM.nextInt(source.size()));
    }

    public static <T> List<T> getRandom(List<T> source, int size) {
        if (source == null || source.isEmpty()) {
            return emptyList();
        }
        List<T> newList = new ArrayList<>(source);
        shuffle(newList, RANDOM);
        return newList.subList(0, min(newList.size(), size));
    }
}

@@ -204,24 +204,53 @@
 .ArrayList;%0A
+import java.util.Collection;%0A
 import java.
@@ -700,48 +700,264 @@
     
-public static %3CT%3E List%3CT%3E getRandom(List
+/**%0A     * use %7B@link #getRandom(Collection, int)%7D%0A     */%0A    @Deprecated%0A    public static %3CT%3E List%3CT%3E getRandom(List%3CT%3E source, int size) %7B%0A        return getRandom((Collection%3CT%3E) source, size);%0A    %7D%0A%0A    public static %3CT%3E List%3CT%3E getRandom(Collection
 %3CT%3E 

add getRandom for Collection.