From: nobu@... Date: 2020-03-10T04:58:01+00:00 Subject: [ruby-dev:50920] [Ruby master Feature#3647] Array#sample(n, replace=false) Issue #3647 has been updated by nobu (Nobuyoshi Nakada). Description updated https://github.com/ruby/ruby/pull/2955 The option name is `replace` for now. ---------------------------------------- Feature #3647: Array#sample(n, replace=false) https://bugs.ruby-lang.org/issues/3647#change-84567 * Author: mrkn (Kenta Murata) * Status: Feedback * Priority: Normal * Assignee: mrkn (Kenta Murata) ---------------------------------------- `Array#sample` does not support sampling with replacement directly, so we must write codes like the following to obtain samples with replacement. ```ruby samples_with_replacement = n.times.map { source.sample } ``` If `Array#sample` has the argument for switching with/without replacement, we can write it as follow. ```ruby samples_with_replacement = source.sample(n, true) ``` The patch was attached. Please consider to merge. ---Files-------------------------------- array_sample_with_replace.patch (3.64 KB) array_sample_with_replace_hash.patch (4.35 KB) array_sample_shuffle.patch (9.62 KB) -- https://bugs.ruby-lang.org/