From: Benoit Daloze Date: 2011-01-07T23:58:54+09:00 Subject: [ruby-core:34225] Re: [Ruby 1.9-Feature#4247][Open] New features for Array#sample, Array#choice On 7 January 2011 14:14, Yusuke ENDOH wrote: > 2011/1/7 Benoit Daloze : >> Did you consider having another option to {each_,}sample to allow replacement ? >> Such as: >> ary.sample 3, replace: true > > The word "replace" gives impression of modification, for those who > are familiar with programming and not familiar with statistics. > Especially, Ruby provides Array#replace. �For example, I imagine the > following behavior: > > �ary = [1, 2, 3] > �p ary.sample(replace: true) #=> 1 > �p ary #=> [2, 3] You are right, it is misleading. Maybe, (I thought originally to that, but I changed seeing your answer in [ruby-dev:42811]) ary.sample(n, replacement: true) is clearer? Or, to be concise and explicit: ary.sample(n, repeat: true) I like this one, what do you think? Boolean flags in a Hash are not so cool though. But just a Symbol flag (sample(n, :repeat, opts)) would complicate too much the method signature. And I think it is still better than having 2 methods. >> Or to follow combinations/permutations: >> ary.repeated_sample 3 > > Hmm. �Is each_repeated_sample OK? I think it is not too bad, but 'repeated_sample' give me the impression there are a few samples, while it is a single one with replacement. >> Off-topic: >> I think it would be nice if some ruby-dev/ruby-core discussions could be merged. >> Even if I cannot currently understand Japanese, I can at least read >> their "coded" ideas. >> I would see that as using the same topic, with both languages. > > Interesting :-) Sure, any concrete idea how that could be made possible?