Class ElementsSequenceGenerator<T>

java.lang.Object
org.jgrapht.util.ElementsSequenceGenerator<T>
Type Parameters:
T - element type
All Implemented Interfaces:
Iterable<T>, Iterator<T>

public class ElementsSequenceGenerator<T> extends Object implements Iterator<T>, Iterable<T>
Generates elements from the input collection in random order.

An element can be generated only once. After all elements have been generated, this generator halts. At every step, an element is generated uniformly at random, which means that every element has an equal probability to be generated. This implementation is based on the Fisher-Yates algorithm. The generator is unbiased meaning the every permutation is equally likely.

Author:
Timofey Chudakov
  • Constructor Details

    • ElementsSequenceGenerator

      public ElementsSequenceGenerator(Collection<T> elements)
      Constructs a new ElementsSequenceGenerator.
      Parameters:
      elements - a collection of elements to generate elements from.
    • ElementsSequenceGenerator

      public ElementsSequenceGenerator(Collection<T> elements, long seed)
      Constructs a new ElementsSequenceGenerator using the specified seed. Two different generators with the same seed will produce identical sequences given that the same collection of elements is provided.
      Parameters:
      elements - a collection of elements to generate elements from.
      seed - a seed for the random number generator
    • ElementsSequenceGenerator

      public ElementsSequenceGenerator(Collection<T> elements, Random rng)
      Constructs a new ElementsSequenceGenerator using the specified random number generator rng. Two different generators will produce identical sequences from a collection of elements given that the random number generator produces the same sequence of numbers.
      Parameters:
      elements - a collection of elements to generate elements from.
      rng - a random number generator
  • Method Details