net.i2p.router.util

## Class RandomIterator<E>

- java.lang.Object
- - net.i2p.router.util.RandomIterator<E>

- Type Parameters:
    `E` - type of elements returned by this iterator
  All Implemented Interfaces:
    Iterator<E>

      public class RandomIterator<E>
      extends Object
      implements Iterator<E>

  Random iterator for efficient early-termination iteration over collections.

  Provides random iteration over a list with the ability to stop iteration early when a condition is met. This can provide significant performance improvements over Collections.shuffle() when the iteration process may terminate before processing all elements.

  Uses BitSet for tracking served items and I2P RandomSource for better randomness distribution. Includes Android compatibility workarounds and proper bounds checking to prevent infinite loops.

  Performance characteristics:

  - O(N) time complexity for iteration setup
  - O(1) average time for next() calls
  - Memory efficient with minimal object allocation

  Note: Not recommended for small lists or when iterating through a large portion of a collection. Use Collections.shuffle() for those cases instead.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RandomIterator(List<E> list)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `hasNext()`
    `E` | `next()`
    `void` | `remove()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.util.Iterator

      `forEachRemaining`

- - ### Constructor Detail

    - #### RandomIterator

          public RandomIterator(List<E> list)

  - ### Method Detail

    - #### hasNext

          public boolean hasNext()

      Specified by:
        `hasNext` in interface `Iterator<E>`

    - #### next

          public E next()

      Specified by:
        `next` in interface `Iterator<E>`

    - #### remove

          public void remove()

      Specified by:
        `remove` in interface `Iterator<E>`
      Throws:
        `UnsupportedOperationException` - always