How would I select a random value (0 to 30) that is not in this array?
var list = new Array(1,3,4,7,8,9);
Build the complementary array and pick random values from it.
var list2 = new Array();
for(var i=0; i<30; i++)
if(!list.contains(i))
list2.push(i);
Then:
var rand = list2[Math.floor(Math.random() * list2.length)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With