Feature request: Array.prototype.random

Michał Wadas michalwadas at gmail.com
Thu Jun 15 21:34:03 UTC 2017

I believe it's too specialized to be a part of Array interface.

Though, I think JS should have better support for randomness, so we could

prng.sample(arr, 5);
prng.sampleWithoutRepetitions(arr, 4);

On 15 Jun 2017 20:42, "Will White" <w.white9 at icloud.com> wrote:

Dear es-discuss,

I would like to propose Array.prototype.random, which would return a random
array element the same way `array[Math.floor(Math.random() *
array.length)]` does, because every time I want a random array element, I
have to remember how to do it. Do you think this is a useful addition to
the language?

Will White
es-discuss mailing list
es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170615/af3153fa/attachment.html>

More information about the es-discuss mailing list