Array#sample(n, replace=false)

Issue #3647 has been updated by yhara (Yutaka HARA).

Target version changed from 2.0.0 to next minor

Feature #3647: Array#sample(n, replace=false)

Author: mrkn (Kenta M.)
Status: Feedback
Priority: Normal
Assignee: mrkn (Kenta M.)
Category: core
Target version: next minor

Array#sample does not support sampling with replacement directly, so we
must write codes like the following to obtain samples with replacement.

samples_with_replacement = { source.sample }

If Array#sample has the argument for switching with/without
replacement, we can write it as follow.

samples_with_replacement = source.sample(n, true)

The patch was attached. Please consider to merge.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs