Class RandomIterator<T>

  • All Implemented Interfaces:
    Iterator<T>


    public class RandomIterator<T>
    extends Object
    implements Iterator<T>
    This is a never-ending iterator that randomly roams over several elements.

    More specifically: this shuffles all the original elements into a list, and then iterates over that shuffled order. Once the end is reached, the list is re-shuffled until the first element is not the last element returned. This way every element will at least get reached once before we randomize everything again.

    • Constructor Detail

      • RandomIterator

        public RandomIterator(T[] array)
      • RandomIterator

        public RandomIterator(Vector<T> v)
    • Method Detail

      • hasNext

        public boolean hasNext()
      • next

        public T next()
      • randomize

        public static void randomize(Object[] list)
        Randomizes the order of this list
      • remove

        public void remove()