[ruby-core:78354] [Ruby trunk Feature#12775] Random subset of array
From:
shyouhei@...
Date:
2016-11-25 13:27:11 UTC
List:
ruby-core #78354
Issue #12775 has been updated by Shyouhei Urabe. We looked at this issue at todays developer meeting but a "random subset with random size" still does not sound familiar to the attendees. Can you show us in code how do you use such array? ---------------------------------------- Feature #12775: Random subset of array https://bugs.ruby-lang.org/issues/12775#change-61720 * Author: Tsuyoshi Sawada * Status: Feedback * Priority: Normal * Assignee: ---------------------------------------- I often see use cases to randomly sample a subset from an array like this: ```ruby a = [3, 2, 6, 2, 6, 1] a.sample(rand(a.length + 1)) # => [2, 6, 6, 3] ``` I request extending `Array#sample` to let it take an option (such as `:arbitrary`) for doing that: ```ruby a.sample(:arbitrary) # => [2, 6, 6, 3] ``` or perhaps having an independent method (like `samples`) to do it. ```ruby a.samples # => [2, 6, 6, 3] ``` -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>