Project

General

Profile

Actions

Misc #14147

closed

Array#sample documentation is unclear about order

Added by StefanPochmann (Stefan Pochmann) over 6 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
[ruby-core:84046]

Description

Does Array#sample only guarantee a random subset, or also random order? It's not clear. I think the current reference implementation does produce random order, but the documentation doesn't guarantee it, so I can't rely on it. If random order is intended, I think the documentation should say so. Maybe say that sample(n) is equivalent to shuffle.take(n)? ("equivalent" meaning same possible outputs with same probabilities)

More details here: https://stackoverflow.com/q/47600931/1672429

Actions

Also available in: Atom PDF

Like0
Like0Like0