Issue #4247 has been updated by trans (Thomas Sawyer).


Whatever happened to #pick and #pick! which picked one random element? The term #sample strongly suggests the return of a subset.

Anther consideration, maybe it would be more useful to use a random delegator.

  enum.random.sample
  enum.random.subset
  enum.random.element
  enum.random.permutations
  ...

There can be many more random functions.

----------------------------------------
Feature #4247: New features for Array#sample, Array#choice
https://bugs.ruby-lang.org/issues/4247#change-25166

Author: oj (Yoji Ojima)
Status: Assigned
Priority: Normal
Assignee: mame (Yusuke Endoh)
Category: 
Target version: 


=begin
 We are planning to add the following features of the random sampling to Array.
 
 1. Weighted random sampling.
 2. Sampling with replacement.
 3. Iteration.
 
 It is discussed in ruby-dev (Feature #3647 and #4147).
 
 
 API will be:
 
 Array#sample([size, [opt]])
   - Random selection without replacement.
   - Returns a new array when size is specified.
   - opt:
       weight: proc or array
       random: Random instance
 
 Array#choice([size, [opt]])
   - Random selection with replacement.
   - Returns a new array when size is specified.
   - opt: same as above.
 
 Array#each_sample([opt])
   - Random selection iterator without replacement.
   - Choose a random element and yield it.
   - Returns an Enumerator if a block is not given.
   - opt: same as above.
 
 Array#each_choice([opt])
   - Random selection iterator with replacement.
   - Choose a random element and yield it.
   - Returns an Enumerator if a block is not given.
   - opt: same as above.
 
 
 Comments?
=end



-- 
http://bugs.ruby-lang.org/