Class CombinationSampler

    • Constructor Detail

      • CombinationSampler

        public CombinationSampler​(UniformRandomProvider rng,
                                  int n,
                                  int k)
        Creates a generator of combinations.

        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 combination of n taken k.

        In contrast to a permutation, the returned array is not guaranteed to be in a random order. The sample() method returns the array in an unspecified order.

        If n <= 0 or k <= 0 or k > n then no combination is required and an exception is raised.

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

      • sample

        public int[] sample()
        Return a combination of k whose entries are selected randomly, without repetition, from the integers 0, 1, ..., n-1 (inclusive).

        The order of the returned array is not guaranteed to be in a random order as the order of a combination does not matter.

        Specified by:
        sample in interface ObjectSampler<int[]>
        Returns:
        a random combination.