mardi 27 décembre 2016

Distributing array elements randomly to new arrays

I have an array of numbers from 1 to 60

var originalArray = [1, 2, 3, 4 .... 58, 59, 60] // etc

I want to - depending on another number between 2 and 4 - split those numbers randomly into the number of arrays specified, and for the result to be unique each and every time.

For example:

distributeArray(2) should result in two arrays, each with 30 numbers randomly selected from the original array.

distributeArray(3) should result in three arrays, each with 20 numbers randomly selected from original array.

I assume this is a reasonably common case so any pointers would be appreciated. Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire