package it.playfellas.superapp.logic;

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

/**
 * Created by affo on 06/08/15.
 */
public class RandomUtils {

    public static <T> List<T> choice(Collection<T> coll, int n) {
        int size = n > coll.size() ? coll.size() : n;
        T[] a = (T[]) coll.toArray();

        List<Integer> indexes = new ArrayList<>();
        for (int i = 0; i < coll.size(); i++) {
            indexes.add(i);
        }

        Collections.shuffle(indexes);
        List<Integer> rndIndexes = indexes.subList(0, size);

        List<T> ret = new ArrayList<>();
        for (Integer i : rndIndexes) {
            ret.add(a[i]);
        }

        return ret;
    }

    public static <T> T choice(Collection<T> coll) {
        return choice(coll, 1).get(0);
    }

    public static <T> T choice(T[] a) {
        return a[(new Random()).nextInt(a.length)];
    }
}

@@ -273,34 +273,25 @@
  choice(
-Collection%3CT%3E coll
+T%5B%5D array
 , int n)
@@ -320,75 +320,39 @@
 n %3E 
-coll.size() ? coll.size() : n;%0A        T%5B%5D a = (T%5B%5D) coll.toArray()
+array.length ? array.length : n
 ;%0A%0A 
@@ -433,19 +433,20 @@
 i %3C 
-coll.size()
+array.length
 ; i+
@@ -690,16 +690,20 @@
 et.add(a
+rray
 %5Bi%5D);%0A  
@@ -805,16 +805,20 @@
   return
+ (T)
  choice(
@@ -825,18 +825,18 @@
 coll
-, 1).get(0
+.toArray()
 );%0A 

fix in signatures