public Item dequeue() {
        if (isEmpty())
            throw new java.util.NoSuchElementException();
        int n = new Random().nextInt(next); // Get an index at random, swap this
                                            // index with "next" index, return
                                            // it's value and remove it.
        exch(a, next - 1, n);
        Item i = a[--next];
        size--;
        if (size > 0 && size == a.length / 4)
            resize(a.length / 2);
        return i;
    }