Package org.apache.commons.rng.sampling
Class SubsetSamplerUtils
java.lang.Object
org.apache.commons.rng.sampling.SubsetSamplerUtils
Utility class for selecting a subset of a sequence of integers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static void
checkSubset
(int n, int k) Checks the subset of lengthk
fromn
is valid.(package private) static int[]
partialSample
(int[] domain, int steps, UniformRandomProvider rng, boolean upper) Perform a partial Fisher-Yates shuffle of the domain in-place and return either the upper fully shuffled section or the remaining lower partially shuffled section.(package private) static void
swap
(int[] array, int i, int j) Swaps the two specified elements in the specified array.
-
Constructor Details
-
SubsetSamplerUtils
private SubsetSamplerUtils()No public construction.
-
-
Method Details
-
checkSubset
static void checkSubset(int n, int k) Checks the subset of lengthk
fromn
is valid.If
n <= 0
ork <= 0
ork > n
then no subset is required and an exception is raised.- Parameters:
n
- Size of the set.k
- Size of the subset.- Throws:
IllegalArgumentException
- ifn <= 0
ork <= 0
ork > n
.
-
partialSample
Perform a partial Fisher-Yates shuffle of the domain in-place and return either the upper fully shuffled section or the remaining lower partially shuffled section.The returned combination will have a length of
steps
forupper=true
, ordomain.length - steps
otherwise.Sampling uses
UniformRandomProvider.nextInt(int)
.- Parameters:
domain
- The domain.steps
- The number of shuffle steps.rng
- Generator of uniformly distributed random numbers.upper
- Set to true to return the upper fully shuffled section.- Returns:
- a random combination.
-
swap
static void swap(int[] array, int i, int j) Swaps the two specified elements in the specified array.- Parameters:
array
- the arrayi
- the first indexj
- the second index
-