package me.xdrop.jrand.utils;

import me.xdrop.jrand.generators.basics.NaturalGenerator;

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

public class Choose {

    private final static NaturalGenerator nat = new NaturalGenerator();

    /**
     * Return a random element from the list
     * @param list The input list
     * @return The random element
     */
    public static <T> T one(List<T> list) {
         int index = nat.range(list.size()).gen();
         return list.get(index);
    }

    /**
     * Return a random element from the list
     * @param arr The input array
     * @return The random element
     */
    public static <T> T one(T[] arr) {
        int index = nat.range(arr.length).gen();
        return arr[index];
    }

    /**
     * Return a random element from the list
     * @return The random element
     */
    public static int one(int[] list) {
        int index = nat.range(list.length).gen();
        return list[index];
    }

    /**
     * Return a random element from the list
     * @return The random element
     */
    public static double one(double[] list) {
        int index = nat.range(list.length).gen();
        return list[index];
    }

    /**
     * Return n random elements from the list (with replacement)
     * @param list Input list
     * @param n Number of elements to retrieve
     * @return A list of random elements
     */
    public static <T> List<T> N(List<T> list, int n) {
        List<Integer> indices = nat.range(list.size()).genMany(n);
        List<T> result = new ArrayList<>();
        for (Integer i : indices) {
            result.add(list.get(i));
        }
        return result;
    }

    /**
     * Return n *unique* random elements from the list (without replacement)
     * @param list Input list
     * @param n Number of elements to return
     * @return A list of unique random elements
     */
    public static <T> List<T> NUnique(List<T> list, int n) {
        List<Integer> indices = nat.sample(n, list.size());
        List<T> result = new ArrayList<>();
        for (Integer i : indices) {
            result.add(list.get(i));
        }
        return result;
    }

    public static <T> List<T> shuffle() {
        throw new UnsupportedOperationException();
    }

    public static <T> List<T> shuffleInplace() {
        throw new UnsupportedOperationException();
    }




}

@@ -487,32 +487,348 @@
 (index);%0A    %7D%0A%0A
+    /**%0A     * Return a random element from any of the lists%0A     * @param list The input list%0A     * @return The random element%0A     */%0A    @SafeVarargs%0A    public static %3CT%3E T one(List%3CT%3E ... lists) %7B%0A        List%3CT%3E chosenList = lists%5Bnat.range(0, lists.length - 1).gen()%5D;%0A        return one(chosenList);%0A    %7D%0A%0A
     /**%0A     * R

Add varargs options to Choose