Package org.apache.commons.rng.sampling
Class SubsetSamplerUtils
- java.lang.Object
-
- org.apache.commons.rng.sampling.SubsetSamplerUtils
-
final class SubsetSamplerUtils extends java.lang.ObjectUtility class for selecting a subset of a sequence of integers.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateSubsetSamplerUtils()No public construction.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static voidcheckSubset(int n, int k)Checks the subset of lengthkfromnis 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 voidswap(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 lengthkfromnis valid.If
n <= 0ork <= 0ork > nthen 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 <= 0ork <= 0ork > 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
stepsforupper=true, ordomain.length - stepsotherwise.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
-
-