- java.lang.Object
-
- org.jgrapht.util.ElementsSequenceGenerator<T>
-
- Type Parameters:
T
- element type
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 Summary
Constructors Constructor Description ElementsSequenceGenerator(Collection<T> elements)
Constructs a newElementsSequenceGenerator
.ElementsSequenceGenerator(Collection<T> elements, long seed)
Constructs a newElementsSequenceGenerator
using the specifiedseed
.ElementsSequenceGenerator(Collection<T> elements, Random rng)
Constructs a newElementsSequenceGenerator
using the specified random number generatorrng
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
Iterator<T>
iterator()
T
next()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Constructor Detail
-
ElementsSequenceGenerator
public ElementsSequenceGenerator(Collection<T> elements)
Constructs a newElementsSequenceGenerator
.- Parameters:
elements
- a collection of elements to generate elements from.
-
ElementsSequenceGenerator
public ElementsSequenceGenerator(Collection<T> elements, long seed)
Constructs a newElementsSequenceGenerator
using the specifiedseed
. 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 newElementsSequenceGenerator
using the specified random number generatorrng
. 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
-
-