|
25 | 25 | import org.cicirello.math.rand.RandomVariates; |
26 | 26 |
|
27 | 27 | /** |
28 | | - * SequenceSampler is a class of utility methods related to efficiently generating random samples of |
29 | | - * array elements, without replacement. |
| 28 | + * An implementation of the SequenceSampler interface is used for generating random samples of array |
| 29 | + * elements, without replacement. |
30 | 30 | * |
31 | 31 | * @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a |
32 | 32 | * href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a> |
33 | 33 | */ |
34 | | -public final class SequenceSampler { |
| 34 | +public interface SequenceSampler { |
35 | 35 |
|
36 | | - /** Class of static utility methods so prevent instantiation with a private constructor. */ |
37 | | - private SequenceSampler() {} |
| 36 | + /** |
| 37 | + * Generates a random sample of k elements, without replacement, from a given source array. All n |
| 38 | + * choose k combinations are equally likely, where n is the length of the source array. |
| 39 | + * |
| 40 | + * @param source The source array to sample. |
| 41 | + * @param k The number of random samples (must be no greater than source.length). |
| 42 | + * @param target An array to hold the result. If target is null or target.length is less than k, |
| 43 | + * then this method will construct a new array for the result. |
| 44 | + * @return An array containing the random sample. |
| 45 | + */ |
| 46 | + int[] nextSample(int[] source, int k, int[] target); |
| 47 | + |
| 48 | + /** |
| 49 | + * Generates a random sample of k elements, without replacement, from a given source array. All n |
| 50 | + * choose k combinations are equally likely, where n is the length of the source array. |
| 51 | + * |
| 52 | + * @param source The source array to sample. |
| 53 | + * @param k The number of random samples (must be no greater than source.length). |
| 54 | + * @param target An array to hold the result. If target is null or target.length is less than k, |
| 55 | + * then this method will construct a new array for the result. |
| 56 | + * @return An array containing the random sample. |
| 57 | + */ |
| 58 | + short[] nextSample(short[] source, int k, short[] target); |
| 59 | + |
| 60 | + /** |
| 61 | + * Generates a random sample of k elements, without replacement, from a given source array. All n |
| 62 | + * choose k combinations are equally likely, where n is the length of the source array. |
| 63 | + * |
| 64 | + * @param source The source array to sample. |
| 65 | + * @param k The number of random samples (must be no greater than source.length). |
| 66 | + * @param target An array to hold the result. If target is null or target.length is less than k, |
| 67 | + * then this method will construct a new array for the result. |
| 68 | + * @return An array containing the random sample. |
| 69 | + */ |
| 70 | + long[] nextSample(long[] source, int k, long[] target); |
| 71 | + |
| 72 | + /** |
| 73 | + * Generates a random sample of k elements, without replacement, from a given source array. All n |
| 74 | + * choose k combinations are equally likely, where n is the length of the source array. |
| 75 | + * |
| 76 | + * @param source The source array to sample. |
| 77 | + * @param k The number of random samples (must be no greater than source.length). |
| 78 | + * @param target An array to hold the result. If target is null or target.length is less than k, |
| 79 | + * then this method will construct a new array for the result. |
| 80 | + * @return An array containing the random sample. |
| 81 | + */ |
| 82 | + byte[] nextSample(byte[] source, int k, byte[] target); |
| 83 | + |
| 84 | + /** |
| 85 | + * Generates a random sample of k elements, without replacement, from a given source array. All n |
| 86 | + * choose k combinations are equally likely, where n is the length of the source array. |
| 87 | + * |
| 88 | + * @param source The source array to sample. |
| 89 | + * @param k The number of random samples (must be no greater than source.length). |
| 90 | + * @param target An array to hold the result. If target is null or target.length is less than k, |
| 91 | + * then this method will construct a new array for the result. |
| 92 | + * @return An array containing the random sample. |
| 93 | + */ |
| 94 | + char[] nextSample(char[] source, int k, char[] target); |
| 95 | + |
| 96 | + /** |
| 97 | + * Generates a random sample of k elements, without replacement, from a given source String. All n |
| 98 | + * choose k combinations are equally likely, where n is the length of the source String. |
| 99 | + * |
| 100 | + * @param source The source String to sample. |
| 101 | + * @param k The number of random samples (must be no greater than source.length). |
| 102 | + * @param target An array to hold the result. If target is null or target.length is less than k, |
| 103 | + * then this method will construct a new array for the result. |
| 104 | + * @return An array containing the random sample. |
| 105 | + */ |
| 106 | + char[] nextSample(String source, int k, char[] target); |
| 107 | + |
| 108 | + /** |
| 109 | + * Generates a random sample of k elements, without replacement, from a given source array. All n |
| 110 | + * choose k combinations are equally likely, where n is the length of the source array. |
| 111 | + * |
| 112 | + * @param source The source array to sample. |
| 113 | + * @param k The number of random samples (must be no greater than source.length). |
| 114 | + * @param target An array to hold the result. If target is null or target.length is less than k, |
| 115 | + * then this method will construct a new array for the result. |
| 116 | + * @return An array containing the random sample. |
| 117 | + */ |
| 118 | + double[] nextSample(double[] source, int k, double[] target); |
| 119 | + |
| 120 | + /** |
| 121 | + * Generates a random sample of k elements, without replacement, from a given source array. All n |
| 122 | + * choose k combinations are equally likely, where n is the length of the source array. |
| 123 | + * |
| 124 | + * @param source The source array to sample. |
| 125 | + * @param k The number of random samples (must be no greater than source.length). |
| 126 | + * @param target An array to hold the result. If target is null or target.length is less than k, |
| 127 | + * then this method will construct a new array for the result. |
| 128 | + * @return An array containing the random sample. |
| 129 | + */ |
| 130 | + float[] nextSample(float[] source, int k, float[] target); |
| 131 | + |
| 132 | + /** |
| 133 | + * Generates a random sample of k elements, without replacement, from a given source array. All n |
| 134 | + * choose k combinations are equally likely, where n is the length of the source array. |
| 135 | + * |
| 136 | + * @param <T> The type of array elements. |
| 137 | + * @param source The source array to sample. |
| 138 | + * @param k The number of random samples (must be no greater than source.length). |
| 139 | + * @param target An array to hold the result. If target is null or target.length is less than k, |
| 140 | + * then this method will construct a new array for the result. |
| 141 | + * @return An array containing the random sample. |
| 142 | + */ |
| 143 | + <T> T[] nextSample(T[] source, int k, T[] target); |
38 | 144 |
|
39 | 145 | /** |
40 | 146 | * Generates a random sample, without replacement, from a given source array with a specified |
|
0 commit comments