Module hash4j

Class PermutationGenerator

java.lang.Object
com.dynatrace.hash4j.random.PermutationGenerator

public final class PermutationGenerator extends Object
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 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:
      true if there are more permutation elements.
    • next

      public int next(PseudoRandomGenerator pseudoRandomGenerator)
      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).