@@ -142,6 +142,124 @@ public interface SequenceSampler {
142142 */
143143 <T > T [] nextSample (T [] source , int k , T [] target );
144144
145+ /**
146+ * Generates a random sample, without replacement, from a given source array with a specified
147+ * probability of an element's inclusion in the sample.
148+ *
149+ * @param source The array from which to sample.
150+ * @param p The probability that element is included in the sample. The expected sample size is
151+ * source.length * p.
152+ * @return An array containing the sample, whose sample size is simply the length of the array.
153+ */
154+ default int [] nextSample (int [] source , double p ) {
155+ return nextSample (source , RandomVariates .nextBinomial (source .length , p ), null );
156+ }
157+
158+ /**
159+ * Generates a random sample, without replacement, from a given source array with a specified
160+ * probability of an element's inclusion in the sample.
161+ *
162+ * @param source The array from which to sample.
163+ * @param p The probability that element is included in the sample. The expected sample size is
164+ * source.length * p.
165+ * @return An array containing the sample, whose sample size is simply the length of the array.
166+ */
167+ default long [] nextSample (long [] source , double p ) {
168+ return nextSample (source , RandomVariates .nextBinomial (source .length , p ), null );
169+ }
170+
171+ /**
172+ * Generates a random sample, without replacement, from a given source array with a specified
173+ * probability of an element's inclusion in the sample.
174+ *
175+ * @param source The array from which to sample.
176+ * @param p The probability that element is included in the sample. The expected sample size is
177+ * source.length * p.
178+ * @return An array containing the sample, whose sample size is simply the length of the array.
179+ */
180+ default short [] nextSample (short [] source , double p ) {
181+ return nextSample (source , RandomVariates .nextBinomial (source .length , p ), null );
182+ }
183+
184+ /**
185+ * Generates a random sample, without replacement, from a given source array with a specified
186+ * probability of an element's inclusion in the sample.
187+ *
188+ * @param source The array from which to sample.
189+ * @param p The probability that element is included in the sample. The expected sample size is
190+ * source.length * p.
191+ * @return An array containing the sample, whose sample size is simply the length of the array.
192+ */
193+ default byte [] nextSample (byte [] source , double p ) {
194+ return nextSample (source , RandomVariates .nextBinomial (source .length , p ), null );
195+ }
196+
197+ /**
198+ * Generates a random sample, without replacement, from a given source array with a specified
199+ * probability of an element's inclusion in the sample.
200+ *
201+ * @param source The array from which to sample.
202+ * @param p The probability that element is included in the sample. The expected sample size is
203+ * source.length * p.
204+ * @return An array containing the sample, whose sample size is simply the length of the array.
205+ */
206+ default double [] nextSample (double [] source , double p ) {
207+ return nextSample (source , RandomVariates .nextBinomial (source .length , p ), null );
208+ }
209+
210+ /**
211+ * Generates a random sample, without replacement, from a given source array with a specified
212+ * probability of an element's inclusion in the sample.
213+ *
214+ * @param source The array from which to sample.
215+ * @param p The probability that element is included in the sample. The expected sample size is
216+ * source.length * p.
217+ * @return An array containing the sample, whose sample size is simply the length of the array.
218+ */
219+ default float [] nextSample (float [] source , double p ) {
220+ return nextSample (source , RandomVariates .nextBinomial (source .length , p ), null );
221+ }
222+
223+ /**
224+ * Generates a random sample, without replacement, from a given source array with a specified
225+ * probability of an element's inclusion in the sample.
226+ *
227+ * @param source The array from which to sample.
228+ * @param p The probability that element is included in the sample. The expected sample size is
229+ * source.length * p.
230+ * @return An array containing the sample, whose sample size is simply the length of the array.
231+ */
232+ default char [] nextSample (char [] source , double p ) {
233+ return nextSample (source , RandomVariates .nextBinomial (source .length , p ), null );
234+ }
235+
236+ /**
237+ * Generates a random sample, without replacement, from a given source String with a specified
238+ * probability of an element's inclusion in the sample.
239+ *
240+ * @param source The String from which to sample.
241+ * @param p The probability that element is included in the sample. The expected sample size is
242+ * source.length() * p.
243+ * @return An array containing the sample, whose sample size is simply the length of the array.
244+ */
245+ default char [] nextSample (String source , double p ) {
246+ return nextSample (source , RandomVariates .nextBinomial (source .length (), p ), null );
247+ }
248+
249+ /**
250+ * Generates a random sample, without replacement, from a given source array with a specified
251+ * probability of an element's inclusion in the sample.
252+ *
253+ * @param <T> The type of array elements.
254+ * @param source The array from which to sample.
255+ * @param p The probability that element is included in the sample. The expected sample size is
256+ * source.length * p.
257+ * @return An array containing the sample, whose sample size is simply the length of the array.
258+ */
259+ default <T > T [] nextSample (T [] source , double p ) {
260+ return nextSample (source , RandomVariates .nextBinomial (source .length , p ), null );
261+ }
262+
145263 /**
146264 * Generates a random sample, without replacement, from a given source array with a specified
147265 * probability of an element's inclusion in the sample.
0 commit comments