public class CombinationSampler extends java.lang.Object implements SharedStateSampler<CombinationSampler>
A combination is a selection of items from a collection, such that (unlike
permutations) the order of selection does not matter. This
sampler can be used to generate a combination in an unspecified order and is
faster than the corresponding
Note that the sample order is unspecified. For example a sample
combination of 2 from 4 may return
[1,0] as the two are
equivalent, and the order of a given combination may change in subsequent samples.
The sampler can be used to generate indices to select subsets where the order of the subset is not important.
Creates a generator of combinations.
|Modifier and Type||Method||Description|
Return a combination of
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.
public CombinationSampler(org.apache.commons.rng.UniformRandomProvider rng, int n, int k)
sample() method will generate an integer array of
k whose entries are selected randomly, without
repetition, from the integers 0, 1, ...,
The returned array represents a combination of
In contrast to a permutation, the returned array is not
guaranteed to be in a random order. The
method returns the array in an unspecified order.
n <= 0 or
k <= 0 or
k > n then no combination
is required and an exception is raised.
rng- Generator of uniformly distributed random numbers.
n- Domain of the combination.
k- Size of the combination.
n <= 0or
k <= 0or
k > n.
public int sample()
kwhose entries are selected randomly, without repetition, from the integers 0, 1, ...,
The order of the returned array is not guaranteed to be in a random order as the order of a combination does not matter.
public CombinationSampler withUniformRandomProvider(org.apache.commons.rng.UniformRandomProvider rng)
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.