Forum: Ruby-core New features for Array#sample, Array#choice

Posted by mame (Yusuke Endoh) (Guest)
on 2012-11-19 18:31
(Received via mailing list)
Issue #4247 has been updated by mame (Yusuke Endoh).

Target version set to next minor

My apologies, I forgot this ticket completely.  I should have wrapped up 
this discussion.
This missed the deadline of 2.0.0.  I'm setting this to next minor. 
Sorry.

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #4247: New features for Array#sample, Array#choice
https://bugs.ruby-lang.org/issues/4247#change-33103

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


=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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.