@@ -199,8 +199,8 @@ pub trait IteratorRandom: Iterator + Sized {
199
199
/// case this equals the number of elements available.
200
200
///
201
201
/// Complexity is `O(n)` where `n` is the length of the iterator.
202
- /// For slices, prefer [`IndexedRandom::choose_multiple `].
203
- fn choose_multiple_fill < R > ( mut self , rng : & mut R , buf : & mut [ Self :: Item ] ) -> usize
202
+ /// For slices, prefer [`IndexedRandom::sample `].
203
+ fn sample_fill < R > ( mut self , rng : & mut R , buf : & mut [ Self :: Item ] ) -> usize
204
204
where
205
205
R : Rng + ?Sized ,
206
206
{
@@ -228,7 +228,7 @@ pub trait IteratorRandom: Iterator + Sized {
228
228
229
229
/// Uniformly sample `amount` distinct elements into a [`Vec`]
230
230
///
231
- /// This is equivalent to `choose_multiple_fill ` except for the result type.
231
+ /// This is equivalent to `sample_fill ` except for the result type.
232
232
///
233
233
/// Although the elements are selected randomly, the order of elements in
234
234
/// the buffer is neither stable nor fully random. If random ordering is
@@ -239,9 +239,9 @@ pub trait IteratorRandom: Iterator + Sized {
239
239
/// elements available.
240
240
///
241
241
/// Complexity is `O(n)` where `n` is the length of the iterator.
242
- /// For slices, prefer [`IndexedRandom::choose_multiple `].
242
+ /// For slices, prefer [`IndexedRandom::sample `].
243
243
#[ cfg( feature = "alloc" ) ]
244
- fn choose_multiple < R > ( mut self , rng : & mut R , amount : usize ) -> Vec < Self :: Item >
244
+ fn sample < R > ( mut self , rng : & mut R , amount : usize ) -> Vec < Self :: Item >
245
245
where
246
246
R : Rng + ?Sized ,
247
247
{
@@ -266,6 +266,25 @@ pub trait IteratorRandom: Iterator + Sized {
266
266
}
267
267
reservoir
268
268
}
269
+
270
+ /// Deprecated: use [`Self::sample_fill`] instead
271
+ #[ deprecated( since = "0.9.2" , note = "Renamed to `sample_fill`" ) ]
272
+ fn choose_multiple_fill < R > ( self , rng : & mut R , buf : & mut [ Self :: Item ] ) -> usize
273
+ where
274
+ R : Rng + ?Sized ,
275
+ {
276
+ self . sample_fill ( rng, buf)
277
+ }
278
+
279
+ /// Deprecated: use [`Self::sample`] instead
280
+ #[ cfg( feature = "alloc" ) ]
281
+ #[ deprecated( since = "0.9.2" , note = "Renamed to `sample`" ) ]
282
+ fn choose_multiple < R > ( self , rng : & mut R , amount : usize ) -> Vec < Self :: Item >
283
+ where
284
+ R : Rng + ?Sized ,
285
+ {
286
+ self . sample ( rng, amount)
287
+ }
269
288
}
270
289
271
290
impl < I > IteratorRandom for I where I : Iterator + Sized { }
@@ -542,8 +561,8 @@ mod test {
542
561
543
562
let mut r = crate :: test:: rng ( 401 ) ;
544
563
let vals = ( min_val..max_val) . collect :: < Vec < i32 > > ( ) ;
545
- let small_sample = vals. iter ( ) . choose_multiple ( & mut r, 5 ) ;
546
- let large_sample = vals. iter ( ) . choose_multiple ( & mut r, vals. len ( ) + 5 ) ;
564
+ let small_sample = vals. iter ( ) . sample ( & mut r, 5 ) ;
565
+ let large_sample = vals. iter ( ) . sample ( & mut r, vals. len ( ) + 5 ) ;
547
566
548
567
assert_eq ! ( small_sample. len( ) , 5 ) ;
549
568
assert_eq ! ( large_sample. len( ) , vals. len( ) ) ;
@@ -650,20 +669,17 @@ mod test {
650
669
}
651
670
652
671
#[ test]
653
- fn value_stability_choose_multiple ( ) {
672
+ fn value_stability_sample ( ) {
654
673
fn do_test < I : Clone + Iterator < Item = u32 > > ( iter : I , v : & [ u32 ] ) {
655
674
let mut rng = crate :: test:: rng ( 412 ) ;
656
675
let mut buf = [ 0u32 ; 8 ] ;
657
- assert_eq ! (
658
- iter. clone( ) . choose_multiple_fill( & mut rng, & mut buf) ,
659
- v. len( )
660
- ) ;
676
+ assert_eq ! ( iter. clone( ) . sample_fill( & mut rng, & mut buf) , v. len( ) ) ;
661
677
assert_eq ! ( & buf[ 0 ..v. len( ) ] , v) ;
662
678
663
679
#[ cfg( feature = "alloc" ) ]
664
680
{
665
681
let mut rng = crate :: test:: rng ( 412 ) ;
666
- assert_eq ! ( iter. choose_multiple ( & mut rng, v. len( ) ) , v) ;
682
+ assert_eq ! ( iter. sample ( & mut rng, v. len( ) ) , v) ;
667
683
}
668
684
}
669
685
0 commit comments