Package org.apache.commons.rng.sampling
Class SubsetSamplerUtils
- java.lang.Object
-
- org.apache.commons.rng.sampling.SubsetSamplerUtils
-
final class SubsetSamplerUtils extends java.lang.Object
Utility class for selecting a subset of a sequence of integers.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
SubsetSamplerUtils()
No public construction.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (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.
-
-
-
Method Detail
-
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:
java.lang.IllegalArgumentException
- ifn <= 0
ork <= 0
ork > n
.
-
partialSample
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.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
-
-