lundi 11 juin 2018

How to choose random N item from an array in Javascript without repetition?

I have an array containing some items, let's say numbers:

[23,4,67,8,29,46,7,2,98]

How it is possibile to choose N different random number (no more, no less) from the array?

Behaviour expected: if N=3

[4,23,98] accepted
[7,67,29] accepted
[7,67,7]  not accepted




Aucun commentaire:

Enregistrer un commentaire