@@ -76,19 +76,19 @@ pub trait SliceRandom {
76
76
/// use rand::seq::SliceRandom;
77
77
///
78
78
/// let mut rng = &mut rand::thread_rng();
79
- /// let sample = "Hello, audience!".as_bytes();
79
+ /// let sequence = "Hello, audience!".as_bytes();
80
80
///
81
81
/// // collect the results into a vector:
82
- /// let v: Vec<u8> = sample.choose_multiple (&mut rng, 3).cloned().collect();
82
+ /// let v: Vec<u8> = sequence.sample (&mut rng, 3).cloned().collect();
83
83
///
84
84
/// // store in a buffer:
85
85
/// let mut buf = [0u8; 5];
86
- /// for (b, slot) in sample.choose_multiple (&mut rng, buf.len()).zip(buf.iter_mut()) {
86
+ /// for (b, slot) in sequence.sample (&mut rng, buf.len()).zip(buf.iter_mut()) {
87
87
/// *slot = *b;
88
88
/// }
89
89
/// ```
90
90
#[ cfg( feature = "alloc" ) ]
91
- fn choose_multiple < R > ( & self , rng : & mut R , amount : usize ) -> SliceChooseIter < Self , Self :: Item >
91
+ fn sample < R > ( & self , rng : & mut R , amount : usize ) -> SliceChooseIter < Self , Self :: Item >
92
92
where R : Rng + ?Sized ;
93
93
94
94
/// Shuffle a mutable slice in place.
@@ -173,7 +173,7 @@ pub trait IteratorRandom: Iterator + Sized {
173
173
/// equals the number of elements available.
174
174
///
175
175
/// Complexity is `O(n)` where `n` is the length of the iterator.
176
- fn choose_multiple_fill < R > ( mut self , rng : & mut R , buf : & mut [ Self :: Item ] )
176
+ fn sample_fill < R > ( mut self , rng : & mut R , buf : & mut [ Self :: Item ] )
177
177
-> usize where R : Rng + ?Sized
178
178
{
179
179
let amount = buf. len ( ) ;
@@ -200,7 +200,7 @@ pub trait IteratorRandom: Iterator + Sized {
200
200
201
201
/// Collects `amount` values at random from the iterator into a vector.
202
202
///
203
- /// This is equivalent to `choose_multiple_fill ` except for the result type.
203
+ /// This is equivalent to `sample_fill ` except for the result type.
204
204
///
205
205
/// Although the elements are selected randomly, the order of elements in
206
206
/// the buffer is neither stable nor fully random. If random ordering is
@@ -212,7 +212,7 @@ pub trait IteratorRandom: Iterator + Sized {
212
212
///
213
213
/// Complexity is `O(n)` where `n` is the length of the iterator.
214
214
#[ cfg( feature = "alloc" ) ]
215
- fn choose_multiple < R > ( mut self , rng : & mut R , amount : usize ) -> Vec < Self :: Item >
215
+ fn sample < R > ( mut self , rng : & mut R , amount : usize ) -> Vec < Self :: Item >
216
216
where R : Rng + ?Sized
217
217
{
218
218
let mut reservoir = Vec :: with_capacity ( amount) ;
@@ -264,7 +264,7 @@ impl<T> SliceRandom for [T] {
264
264
}
265
265
266
266
#[ cfg( feature = "alloc" ) ]
267
- fn choose_multiple < R > ( & self , rng : & mut R , amount : usize ) -> SliceChooseIter < Self , Self :: Item >
267
+ fn sample < R > ( & self , rng : & mut R , amount : usize ) -> SliceChooseIter < Self , Self :: Item >
268
268
where R : Rng + ?Sized
269
269
{
270
270
let amount = :: core:: cmp:: min ( amount, self . len ( ) ) ;
@@ -306,8 +306,8 @@ impl<T> SliceRandom for [T] {
306
306
impl < I > IteratorRandom for I where I : Iterator + Sized { }
307
307
308
308
309
- /// Iterator over multiple choices, as returned by [`SliceRandom::choose_multiple ](
310
- /// trait.SliceRandom.html#method.choose_multiple ).
309
+ /// Iterator over multiple choices, as returned by [`SliceRandom::sample ](
310
+ /// trait.SliceRandom.html#method.sample ).
311
311
#[ cfg( feature = "alloc" ) ]
312
312
#[ derive( Debug ) ]
313
313
pub struct SliceChooseIter < ' a , S : ?Sized + ' a , T : ' a > {
@@ -346,18 +346,18 @@ impl<'a, S: Index<usize, Output = T> + ?Sized + 'a, T: 'a> ExactSizeIterator
346
346
347
347
/// Randomly sample `amount` elements from a finite iterator.
348
348
///
349
- /// Deprecated: use [`IteratorRandom::choose_multiple `] instead.
349
+ /// Deprecated: use [`IteratorRandom::sample `] instead.
350
350
///
351
- /// [`IteratorRandom::choose_multiple `]: trait.IteratorRandom.html#method.choose_multiple
351
+ /// [`IteratorRandom::sample `]: trait.IteratorRandom.html#method.sample
352
352
#[ cfg( feature = "alloc" ) ]
353
- #[ deprecated( since="0.6.0" , note="use IteratorRandom::choose_multiple instead" ) ]
353
+ #[ deprecated( since="0.6.0" , note="use IteratorRandom::sample instead" ) ]
354
354
pub fn sample_iter < T , I , R > ( rng : & mut R , iterable : I , amount : usize ) -> Result < Vec < T > , Vec < T > >
355
355
where I : IntoIterator < Item =T > ,
356
356
R : Rng + ?Sized ,
357
357
{
358
358
use seq:: IteratorRandom ;
359
359
let iter = iterable. into_iter ( ) ;
360
- let result = iter. choose_multiple ( rng, amount) ;
360
+ let result = iter. sample ( rng, amount) ;
361
361
if result. len ( ) == amount {
362
362
Ok ( result)
363
363
} else {
@@ -373,11 +373,11 @@ pub fn sample_iter<T, I, R>(rng: &mut R, iterable: I, amount: usize) -> Result<V
373
373
///
374
374
/// Panics if `amount > slice.len()`
375
375
///
376
- /// Deprecated: use [`SliceRandom::choose_multiple `] instead.
376
+ /// Deprecated: use [`SliceRandom::sample `] instead.
377
377
///
378
- /// [`SliceRandom::choose_multiple `]: trait.SliceRandom.html#method.choose_multiple
378
+ /// [`SliceRandom::sample `]: trait.SliceRandom.html#method.sample
379
379
#[ cfg( feature = "alloc" ) ]
380
- #[ deprecated( since="0.6.0" , note="use SliceRandom::choose_multiple instead" ) ]
380
+ #[ deprecated( since="0.6.0" , note="use SliceRandom::sample instead" ) ]
381
381
pub fn sample_slice < R , T > ( rng : & mut R , slice : & [ T ] , amount : usize ) -> Vec < T >
382
382
where R : Rng + ?Sized ,
383
383
T : Clone
@@ -397,11 +397,11 @@ pub fn sample_slice<R, T>(rng: &mut R, slice: &[T], amount: usize) -> Vec<T>
397
397
///
398
398
/// Panics if `amount > slice.len()`
399
399
///
400
- /// Deprecated: use [`SliceRandom::choose_multiple `] instead.
400
+ /// Deprecated: use [`SliceRandom::sample `] instead.
401
401
///
402
- /// [`SliceRandom::choose_multiple `]: trait.SliceRandom.html#method.choose_multiple
402
+ /// [`SliceRandom::sample `]: trait.SliceRandom.html#method.sample
403
403
#[ cfg( feature = "alloc" ) ]
404
- #[ deprecated( since="0.6.0" , note="use SliceRandom::choose_multiple instead" ) ]
404
+ #[ deprecated( since="0.6.0" , note="use SliceRandom::sample instead" ) ]
405
405
pub fn sample_slice_ref < ' a , R , T > ( rng : & mut R , slice : & ' a [ T ] , amount : usize ) -> Vec < & ' a T >
406
406
where R : Rng + ?Sized
407
407
{
@@ -584,8 +584,8 @@ mod test {
584
584
585
585
let mut r = :: test:: rng ( 401 ) ;
586
586
let vals = ( min_val..max_val) . collect :: < Vec < i32 > > ( ) ;
587
- let small_sample = vals. iter ( ) . choose_multiple ( & mut r, 5 ) ;
588
- let large_sample = vals. iter ( ) . choose_multiple ( & mut r, vals. len ( ) + 5 ) ;
587
+ let small_sample = vals. iter ( ) . sample ( & mut r, 5 ) ;
588
+ let large_sample = vals. iter ( ) . sample ( & mut r, vals. len ( ) + 5 ) ;
589
589
590
590
assert_eq ! ( small_sample. len( ) , 5 ) ;
591
591
assert_eq ! ( large_sample. len( ) , vals. len( ) ) ;
0 commit comments