java.lang.Object
com.dynatrace.hash4j.random.PermutationGenerator
A permutation generator.
Generators random permutations element by element based on Fisher-Yates shuffling. The generator can be reused after resetting to generate multiple permutations without additional object allocations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanhasNext()Test if there are more permutation elements.intnext(PseudoRandomGenerator pseudoRandomGenerator) Returns the next element of the permutation.voidreset()Resets this permutation generator.
-
Constructor Details
-
PermutationGenerator
public PermutationGenerator(int size) Constructor.- Parameters:
size- the number of elements
-
-
Method Details
-
hasNext
public boolean hasNext()Test if there are more permutation elements.The number of permutation elements equals the size defined when constructing this permutation generator.
- Returns:
trueif there are more permutation elements.
-
next
Returns the next element of the permutation.- Parameters:
pseudoRandomGenerator- a pseudo-random generator- Returns:
- the next element of the permutation
-
reset
public void reset()Resets this permutation generator.Must be called before starting a new iteration over the permutated elements using
next(PseudoRandomGenerator).
-