vendredi 6 octobre 2017

Random selection and repeat a specific amount of times for each selection

I want to get a random selected item from an array up till how many maximum repeat time specified.

var array = ["cat", "dog"];
var maxRepeat = 10;

I want to return cat and dog each 10 times which make a total of 20 times in a random order. Something like:

cat
cat
dog
cat
dog
dog
cat
cat
dog
cat
dog
dog
dog
cat
cat
dog
cat
cat
dog
dog




Aucun commentaire:

Enregistrer un commentaire