From: Akzhan Abdulin Date: 2016-09-20T22:30:27+03:00 Subject: [ruby-core:77330] Re: [Ruby trunk Feature#12775] Random subset of array --===============0259773592== Content-Type: multipart/alternative; boundary=94eb2c1a0770072d87053cf576a2 --94eb2c1a0770072d87053cf576a2 Content-Type: text/plain; charset=UTF-8 I think it should be not in Ruby core but in testing frameworks or in form of separate gem. 2016-09-20 9:05 GMT+03:00 : > Issue #12775 has been updated by Tsuyoshi Sawada. > > > Nobuyoshi Nakada wrote: > > Do you mean random size subset? > > I can't get how/why it is useful. > > Please elaborate with the use cases. > > Yes, I mean random subset with random size. The use cases are mainly for > testing. > > ---------------------------------------- > Feature #12775: Random subset of array > https://bugs.ruby-lang.org/issues/12775#change-60571 > > * 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: > > --94eb2c1a0770072d87053cf576a2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I think it should be not in Ruby core but in testing frame= works or in form of separate gem.

2016-09-20 9:05 GMT+03:00 <sawadatsuyoshi@gm= ail.com>:
Issue #12775 has = been updated by Tsuyoshi Sawada.


Nobuyoshi Nakada wrote:
> Do you mean random size subset?
> I can't get how/why it is useful.
> Please elaborate with the use cases.

Yes, I mean random subset with random size. The use cases are mainly= for testing.

----------------------------------------
Feature #12775: Random subset of array
https://bugs.ruby-lang.org/issues/12= 775#change-60571

* Author: Tsuyoshi Sawada
* Status: Feedback
* Priority: Normal
* Assignee:
----------------------------------------
I often see use cases to randomly sample a subset from an array like this:<= br>
```ruby
a =3D [3, 2, 6, 2, 6, 1]
a.sample(rand(a.length + 1)) # =3D> [2, 6, 6, 3]
```

I request extending `Array#sample` to let it take an option (such as `:arbi= trary`) for doing that:

```ruby
a.sample(:arbitrary) # =3D> [2, 6, 6, 3]
```

or perhaps having an independent method (like `samples`) to do it.

```ruby
a.samples # =3D> [2, 6, 6, 3]
```




--
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:= ruby-core-request@ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-= bin/mailman/options/ruby-core>

--94eb2c1a0770072d87053cf576a2-- --===============0259773592== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============0259773592==--