Class PermutationSampler

java.lang.Object
org.apache.commons.rng.sampling.PermutationSampler
All Implemented Interfaces:
ObjectSampler<int[]>, SharedStateObjectSampler<int[]>, SharedStateSampler<SharedStateObjectSampler<int[]>>

public class PermutationSampler extends Object implements SharedStateObjectSampler<int[]>
Class for representing permutations of a sequence of integers.

Sampling uses UniformRandomProvider.nextInt(int).

This class also contains utilities for shuffling an int[] array in-place.

  • Constructor Details

    • PermutationSampler

      public PermutationSampler(UniformRandomProvider rng, int n, int k)
      Creates a generator of permutations.

      The sample() method will generate an integer array of length k whose entries are selected randomly, without repetition, from the integers 0, 1, ..., n-1 (inclusive). The returned array represents a permutation of n taken k.

      Parameters:
      rng - Generator of uniformly distributed random numbers.
      n - Domain of the permutation.
      k - Size of the permutation.
      Throws:
      IllegalArgumentException - if n <= 0 or k <= 0 or k > n.
  • Method Details