vendredi 27 octobre 2017

How do I avoid specific 3 element combinations using rand and split function?

I have a variable with 7 elements and I need to select 3 elements at random, but here are specific 3 element combinations i want it to avoid. How do I code this? (ex. I need it to avoid the combination [2,5,7] and [1,3,6])

This is what i have so far:

var Allregions = [
'1'
'2'
'3'
'4'
'5'
'6'
'7']


var ShowRegions = [];
    do {
      ShowRegions [ShowRegions.length] = Allregions.splice(
                            Math.floor(Math.random() * Allregions.length)
                          , 1)[0];
} while (ShowRegions.length < 3);




Aucun commentaire:

Enregistrer un commentaire