private int partition(E[] array, int begin, int end) {
        int index = begin + random.nextInt(end - begin + 1);
        E pivot = array[index];
        swap(array, index, end);

        for (int j = index = begin; j < end; j++) {
            if (array[j].compareTo(pivot) <= 0) {
                swap(array, index++, j);
            }
        }

        swap(array, index, end);
        return index;
    }