-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]sample(byte[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.static byte[]sample(byte[] source, int k, byte[] target) Generates a random sample of k elements, without replacement, from a given source array.static char[]sample(char[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.static char[]sample(char[] source, int k, char[] target) Generates a random sample of k elements, without replacement, from a given source array.static double[]sample(double[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.static double[]sample(double[] source, int k, double[] target) Generates a random sample of k elements, without replacement, from a given source array.static float[]sample(float[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.static float[]sample(float[] source, int k, float[] target) Generates a random sample of k elements, without replacement, from a given source array.static int[]sample(int[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.static int[]sample(int[] source, int k, int[] target) Generates a random sample of k elements, without replacement, from a given source array.static long[]sample(long[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.static long[]sample(long[] source, int k, long[] target) Generates a random sample of k elements, without replacement, from a given source array.static short[]sample(short[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.static short[]sample(short[] source, int k, short[] target) Generates a random sample of k elements, without replacement, from a given source array.static char[]Generates a random sample, without replacement, from a given String with a specified probability of a character's inclusion in the sample.static char[]Generates a random sample of k chars, without replacement, from a given source String.static <T> T[]sample(T[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.static <T> T[]sample(T[] source, int k, T[] target) Generates a random sample of k elements, without replacement, from a given source array.static byte[]sampleInsertion(byte[] source, int k, byte[] target) Deprecated.static char[]sampleInsertion(char[] source, int k, char[] target) Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.static double[]sampleInsertion(double[] source, int k, double[] target) Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.static float[]sampleInsertion(float[] source, int k, float[] target) Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.static int[]sampleInsertion(int[] source, int k, int[] target) Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.static long[]sampleInsertion(long[] source, int k, long[] target) Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.static short[]sampleInsertion(short[] source, int k, short[] target) Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.static char[]sampleInsertion(String source, int k, char[] target) Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.static <T> T[]sampleInsertion(T[] source, int k, T[] target) Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.static byte[]samplePool(byte[] source, int k, byte[] target) Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.static char[]samplePool(char[] source, int k, char[] target) Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.static double[]samplePool(double[] source, int k, double[] target) Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.static float[]samplePool(float[] source, int k, float[] target) Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.static int[]samplePool(int[] source, int k, int[] target) Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.static long[]samplePool(long[] source, int k, long[] target) Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.static short[]samplePool(short[] source, int k, short[] target) Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.static char[]samplePool(String source, int k, char[] target) Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.static <T> T[]samplePool(T[] source, int k, T[] target) Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.static byte[]sampleReservoir(byte[] source, int k, byte[] target) Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.static char[]sampleReservoir(char[] source, int k, char[] target) Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.static double[]sampleReservoir(double[] source, int k, double[] target) Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.static float[]sampleReservoir(float[] source, int k, float[] target) Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.static int[]sampleReservoir(int[] source, int k, int[] target) Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.static long[]sampleReservoir(long[] source, int k, long[] target) Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.static short[]sampleReservoir(short[] source, int k, short[] target) Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.static char[]sampleReservoir(String source, int k, char[] target) Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.static <T> T[]sampleReservoir(T[] source, int k, T[] target) Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.
-
Method Details
-
sample
public static byte[] sample(byte[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.- Parameters:
source- The array from which to sample.p- The probability that element is included in the sample. The expected sample size is source.length * p.- Returns:
- An array containing the sample, whose sample size is simply the length of the array.
-
sample
public static char[] sample(char[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.- Parameters:
source- The array from which to sample.p- The probability that element is included in the sample. The expected sample size is source.length * p.- Returns:
- An array containing the sample, whose sample size is simply the length of the array.
-
sample
public static double[] sample(double[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.- Parameters:
source- The array from which to sample.p- The probability that element is included in the sample. The expected sample size is source.length * p.- Returns:
- An array containing the sample, whose sample size is simply the length of the array.
-
sample
public static float[] sample(float[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.- Parameters:
source- The array from which to sample.p- The probability that element is included in the sample. The expected sample size is source.length * p.- Returns:
- An array containing the sample, whose sample size is simply the length of the array.
-
sample
public static int[] sample(int[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.- Parameters:
source- The array from which to sample.p- The probability that element is included in the sample. The expected sample size is source.length * p.- Returns:
- An array containing the sample, whose sample size is simply the length of the array.
-
sample
public static long[] sample(long[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.- Parameters:
source- The array from which to sample.p- The probability that element is included in the sample. The expected sample size is source.length * p.- Returns:
- An array containing the sample, whose sample size is simply the length of the array.
-
sample
public static short[] sample(short[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.- Parameters:
source- The array from which to sample.p- The probability that element is included in the sample. The expected sample size is source.length * p.- Returns:
- An array containing the sample, whose sample size is simply the length of the array.
-
sample
Generates a random sample, without replacement, from a given String with a specified probability of a character's inclusion in the sample.- Parameters:
source- The String from which to sample.p- The probability that a character is included in the sample. The expected sample size is source.length() * p.- Returns:
- An array containing the sample, whose sample size is simply the length of the array.
-
sample
public static <T> T[] sample(T[] source, double p) Generates a random sample, without replacement, from a given source array with a specified probability of an element's inclusion in the sample.- Type Parameters:
T- The type of array elements.- Parameters:
source- The array from which to sample.p- The probability that element is included in the sample. The expected sample size is source.length * p.- Returns:
- An array containing the sample, whose sample size is simply the length of the array.
-
sample
public static int[] sample(int[] source, int k, int[] target) Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This method chooses among the
SequencePoolSampler,SequenceReservoirSampler, andSequenceInsertionSamplerclasses based on the values of n and k.This approach combining reservoir sampling, pool sampling, and insertion sampling was described in: Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(min(n, k2)) and it generates O(min(k, n-k)) random numbers.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sample
public static long[] sample(long[] source, int k, long[] target) Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This method chooses among the
SequencePoolSampler,SequenceReservoirSampler, andSequenceInsertionSamplerclasses based on the values of n and k.This approach combining reservoir sampling, pool sampling, and insertion sampling was described in: Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(min(n, k2)) and it generates O(min(k, n-k)) random numbers.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sample
public static short[] sample(short[] source, int k, short[] target) Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This method chooses among the
SequencePoolSampler,SequenceReservoirSampler, andSequenceInsertionSamplerclasses based on the values of n and k.This approach combining reservoir sampling, pool sampling, and insertion sampling was described in: Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(min(n, k2)) and it generates O(min(k, n-k)) random numbers.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sample
public static byte[] sample(byte[] source, int k, byte[] target) Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This method chooses among the
SequencePoolSampler,SequenceReservoirSampler, andSequenceInsertionSamplerclasses based on the values of n and k.This approach combining reservoir sampling, pool sampling, and insertion sampling was described in: Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(min(n, k2)) and it generates O(min(k, n-k)) random numbers.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sample
public static char[] sample(char[] source, int k, char[] target) Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This method chooses among the
SequencePoolSampler,SequenceReservoirSampler, andSequenceInsertionSamplerclasses based on the values of n and k.This approach combining reservoir sampling, pool sampling, and insertion sampling was described in: Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(min(n, k2)) and it generates O(min(k, n-k)) random numbers.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sample
Generates a random sample of k chars, without replacement, from a given source String. All n choose k combinations are equally likely, where n is the length of the source String.This method chooses among the
SequencePoolSampler,SequenceReservoirSampler, andSequenceInsertionSamplerclasses based on the values of n and k.This approach combining reservoir sampling, pool sampling, and insertion sampling was described in: Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(min(n, k2)) and it generates O(min(k, n-k)) random numbers.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length()).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.length()NegativeArraySizeException- if k < 0
-
sample
public static double[] sample(double[] source, int k, double[] target) Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This method chooses among the
SequencePoolSampler,SequenceReservoirSampler, andSequenceInsertionSamplerclasses based on the values of n and k.This approach combining reservoir sampling, pool sampling, and insertion sampling was described in: Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(min(n, k2)) and it generates O(min(k, n-k)) random numbers.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sample
public static float[] sample(float[] source, int k, float[] target) Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This method chooses among the
SequencePoolSampler,SequenceReservoirSampler, andSequenceInsertionSamplerclasses based on the values of n and k.This approach combining reservoir sampling, pool sampling, and insertion sampling was described in: Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(min(n, k2)) and it generates O(min(k, n-k)) random numbers.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sample
public static <T> T[] sample(T[] source, int k, T[] target) Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This method chooses among the
SequencePoolSampler,SequenceReservoirSampler, andSequenceInsertionSamplerclasses based on the values of n and k.This approach combining reservoir sampling, pool sampling, and insertion sampling was described in: Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(min(n, k2)) and it generates O(min(k, n-k)) random numbers.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Type Parameters:
T- The type of array elements.- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleReservoir
Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.Uses the reservoir sampling algorithm (Algorithm R) from J. Vitter's 1985 article "Random Sampling with a Reservoir" from ACM Transactions on Mathematical Software. The runtime is O(n) and it generates O(n-k) random numbers. Thus, it is an especially good choice as k approaches n. Only constant extra space required.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleReservoir
Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.Uses the reservoir sampling algorithm (Algorithm R) from J. Vitter's 1985 article "Random Sampling with a Reservoir" from ACM Transactions on Mathematical Software. The runtime is O(n) and it generates O(n-k) random numbers. Thus, it is an especially good choice as k approaches n. Only constant extra space required.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleReservoir
Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.Uses the reservoir sampling algorithm (Algorithm R) from J. Vitter's 1985 article "Random Sampling with a Reservoir" from ACM Transactions on Mathematical Software. The runtime is O(n) and it generates O(n-k) random numbers. Thus, it is an especially good choice as k approaches n. Only constant extra space required.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleReservoir
Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.Uses the reservoir sampling algorithm (Algorithm R) from J. Vitter's 1985 article "Random Sampling with a Reservoir" from ACM Transactions on Mathematical Software. The runtime is O(n) and it generates O(n-k) random numbers. Thus, it is an especially good choice as k approaches n. Only constant extra space required.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleReservoir
Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.Uses the reservoir sampling algorithm (Algorithm R) from J. Vitter's 1985 article "Random Sampling with a Reservoir" from ACM Transactions on Mathematical Software. The runtime is O(n) and it generates O(n-k) random numbers. Thus, it is an especially good choice as k approaches n. Only constant extra space required.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleReservoir
Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.Generates a random sample of k chars, without replacement, from a given source String. All n choose k combinations are equally likely, where n is the length of the source String.Uses the reservoir sampling algorithm (Algorithm R) from J. Vitter's 1985 article "Random Sampling with a Reservoir" from ACM Transactions on Mathematical Software. The runtime is O(n) and it generates O(n-k) random numbers. Thus, it is an especially good choice as k approaches n. Only constant extra space required.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length()).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.length()NegativeArraySizeException- if k < 0
-
sampleReservoir
Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.Uses the reservoir sampling algorithm (Algorithm R) from J. Vitter's 1985 article "Random Sampling with a Reservoir" from ACM Transactions on Mathematical Software. The runtime is O(n) and it generates O(n-k) random numbers. Thus, it is an especially good choice as k approaches n. Only constant extra space required.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleReservoir
Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.Uses the reservoir sampling algorithm (Algorithm R) from J. Vitter's 1985 article "Random Sampling with a Reservoir" from ACM Transactions on Mathematical Software. The runtime is O(n) and it generates O(n-k) random numbers. Thus, it is an especially good choice as k approaches n. Only constant extra space required.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleReservoir
Deprecated.This method is deprecated, and replaced by theSequenceReservoirSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.Uses the reservoir sampling algorithm (Algorithm R) from J. Vitter's 1985 article "Random Sampling with a Reservoir" from ACM Transactions on Mathematical Software. The runtime is O(n) and it generates O(n-k) random numbers. Thus, it is an especially good choice as k approaches n. Only constant extra space required.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Type Parameters:
T- The type of array elements.- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
samplePool
Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the algorithm SELECT of S. Goodman and S. Hedetniemi, as described in: J Ernvall, O Nevalainen, "An Algorithm for Unbiased Random Sampling," The Computer Journal, 25(1):45-47, 1982.
The runtime is O(n) and it generates O(k) random numbers. Thus, it is a better choice than sampleReservoir when k < n-k. However, this uses O(n) extra space, whereas the reservoir algorithm uses no extra space.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
samplePool
Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the algorithm SELECT of S. Goodman and S. Hedetniemi, as described in: J Ernvall, O Nevalainen, "An Algorithm for Unbiased Random Sampling," The Computer Journal, 25(1):45-47, 1982.
The runtime is O(n) and it generates O(k) random numbers. Thus, it is a better choice than sampleReservoir when k < n-k. However, this uses O(n) extra space, whereas the reservoir algorithm uses no extra space.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
samplePool
Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the algorithm SELECT of S. Goodman and S. Hedetniemi, as described in: J Ernvall, O Nevalainen, "An Algorithm for Unbiased Random Sampling," The Computer Journal, 25(1):45-47, 1982.
The runtime is O(n) and it generates O(k) random numbers. Thus, it is a better choice than sampleReservoir when k < n-k. However, this uses O(n) extra space, whereas the reservoir algorithm uses no extra space.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
samplePool
Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the algorithm SELECT of S. Goodman and S. Hedetniemi, as described in: J Ernvall, O Nevalainen, "An Algorithm for Unbiased Random Sampling," The Computer Journal, 25(1):45-47, 1982.
The runtime is O(n) and it generates O(k) random numbers. Thus, it is a better choice than sampleReservoir when k < n-k. However, this uses O(n) extra space, whereas the reservoir algorithm uses no extra space.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
samplePool
Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the algorithm SELECT of S. Goodman and S. Hedetniemi, as described in: J Ernvall, O Nevalainen, "An Algorithm for Unbiased Random Sampling," The Computer Journal, 25(1):45-47, 1982.
The runtime is O(n) and it generates O(k) random numbers. Thus, it is a better choice than sampleReservoir when k < n-k. However, this uses O(n) extra space, whereas the reservoir algorithm uses no extra space.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
samplePool
Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.Generates a random sample of k chars, without replacement, from a given source String. All n choose k combinations are equally likely, where n is the length of the source String.This implements the algorithm SELECT of S. Goodman and S. Hedetniemi, as described in: J Ernvall, O Nevalainen, "An Algorithm for Unbiased Random Sampling," The Computer Journal, 25(1):45-47, 1982.
The runtime is O(n) and it generates O(k) random numbers. Thus, it is a better choice than sampleReservoir when k < n-k. However, this uses O(n) extra space, whereas the reservoir algorithm uses no extra space.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source to sample.k- The number of random samples (must be no greater than source.length()).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.length()NegativeArraySizeException- if k < 0
-
samplePool
Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the algorithm SELECT of S. Goodman and S. Hedetniemi, as described in: J Ernvall, O Nevalainen, "An Algorithm for Unbiased Random Sampling," The Computer Journal, 25(1):45-47, 1982.
The runtime is O(n) and it generates O(k) random numbers. Thus, it is a better choice than sampleReservoir when k < n-k. However, this uses O(n) extra space, whereas the reservoir algorithm uses no extra space.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
samplePool
Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the algorithm SELECT of S. Goodman and S. Hedetniemi, as described in: J Ernvall, O Nevalainen, "An Algorithm for Unbiased Random Sampling," The Computer Journal, 25(1):45-47, 1982.
The runtime is O(n) and it generates O(k) random numbers. Thus, it is a better choice than sampleReservoir when k < n-k. However, this uses O(n) extra space, whereas the reservoir algorithm uses no extra space.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
samplePool
Deprecated.This method is deprecated, and replaced by theSequencePoolSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the algorithm SELECT of S. Goodman and S. Hedetniemi, as described in: J Ernvall, O Nevalainen, "An Algorithm for Unbiased Random Sampling," The Computer Journal, 25(1):45-47, 1982.
The runtime is O(n) and it generates O(k) random numbers. Thus, it is a better choice than sampleReservoir when k < n-k. However, this uses O(n) extra space, whereas the reservoir algorithm uses no extra space.
This method is safe to use with threads, as it uses ThreadLocalRandom as the underlying source of randomness.
- Type Parameters:
T- The type of array elements.- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleInsertion
Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the insertion sampling algorithm described in:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(k2) and it generates O(k) random numbers. Thus, it is a better choice than both sampleReservoir and samplePool when k2 < n. Just like sampleReservoir, the sampleInsertion method only requires O(1) extra space, while samplePool requires O(n) extra space.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleInsertion
Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the insertion sampling algorithm described in:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(k2) and it generates O(k) random numbers. Thus, it is a better choice than both sampleReservoir and samplePool when k2 < n. Just like sampleReservoir, the sampleInsertion method only requires O(1) extra space, while samplePool requires O(n) extra space.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleInsertion
Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the insertion sampling algorithm described in:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(k2) and it generates O(k) random numbers. Thus, it is a better choice than both sampleReservoir and samplePool when k2 < n. Just like sampleReservoir, the sampleInsertion method only requires O(1) extra space, while samplePool requires O(n) extra space.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleInsertion
Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the insertion sampling algorithm described in:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(k2) and it generates O(k) random numbers. Thus, it is a better choice than both sampleReservoir and samplePool when k2 < n. Just like sampleReservoir, the sampleInsertion method only requires O(1) extra space, while samplePool requires O(n) extra space.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleInsertion
Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the insertion sampling algorithm described in:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(k2) and it generates O(k) random numbers. Thus, it is a better choice than both sampleReservoir and samplePool when k2 < n. Just like sampleReservoir, the sampleInsertion method only requires O(1) extra space, while samplePool requires O(n) extra space.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleInsertion
Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.Generates a random sample of k chars, without replacement, from a given source String. All n choose k combinations are equally likely, where n is the length of the source String.This implements the insertion sampling algorithm described in:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(k2) and it generates O(k) random numbers. Thus, it is a better choice than both sampleReservoir and samplePool when k2 < n. Just like sampleReservoir, the sampleInsertion method only requires O(1) extra space, while samplePool requires O(n) extra space.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source to sample.k- The number of random samples (must be no greater than source.length()).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.length()NegativeArraySizeException- if k < 0
-
sampleInsertion
Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the insertion sampling algorithm described in:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(k2) and it generates O(k) random numbers. Thus, it is a better choice than both sampleReservoir and samplePool when k2 < n. Just like sampleReservoir, the sampleInsertion method only requires O(1) extra space, while samplePool requires O(n) extra space.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleInsertion
Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the insertion sampling algorithm described in:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(k2) and it generates O(k) random numbers. Thus, it is a better choice than both sampleReservoir and samplePool when k2 < n. Just like sampleReservoir, the sampleInsertion method only requires O(1) extra space, while samplePool requires O(n) extra space.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
sampleInsertion
Deprecated.This method is deprecated, and replaced by theSequenceInsertionSamplerclass.Generates a random sample of k elements, without replacement, from a given source array. All n choose k combinations are equally likely, where n is the length of the source array.This implements the insertion sampling algorithm described in:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
The runtime is O(k2) and it generates O(k) random numbers. Thus, it is a better choice than both sampleReservoir and samplePool when k2 < n. Just like sampleReservoir, the sampleInsertion method only requires O(1) extra space, while samplePool requires O(n) extra space.
This method uses ThreadLocalRandom as the pseudorandom number generator, and is thus safe, and efficient (i.e., non-blocking), for use with threads.
- Type Parameters:
T- The type of array elements.- Parameters:
source- The source array to sample.k- The number of random samples (must be no greater than source.length).target- An array to hold the result. If target is null or target.length is less than k, then this method will construct a new array for the result.- Returns:
- An array containing the random sample.
- Throws:
IllegalArgumentException- if k > source.lengthNegativeArraySizeException- if k < 0
-
SequenceInsertionSamplerclass.