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);
EDIT: I wanted to clarify something: The "numbers" are just placeholders, as they are actually calling elements from different parts of the code. i.e. 1 is actually something like "page banner". So the code I had written was fine in selecting 3 unique elements to populate a webpage, but it didn't allow me to control which 3 element combination is (not)shown.