public static int randomSelect(List<Integer> list, int index) {

        Random rand = new Random();
        int partIndex = rand.nextInt(list.size());

        int q = list.get(partIndex);
        int qIndex = list.indexOf(q);
        List<Integer> partitionList = new ArrayList<Integer>();
        partitionList.add(q);

        int beforeRank = 0;

        for (int i = 0; i < list.size(); i++) {
            if (i == qIndex) {
                continue;
            }
            Integer value = list.get(i);
            if (value < q) {
                partitionList.add(0, value);
                beforeRank++;
            } else {
                partitionList.add(partitionList.size(), value);
            }
        }        

        if (beforeRank > index) {
            return randomSelect(partitionList.subList(0, beforeRank), index);
        } else if (beforeRank < index) {
            return randomSelect(partitionList.subList(beforeRank + 1, list.size()), index - beforeRank - 1);
        } else {
            return q;
        }
    }