I\'m generating random numbers from 1 to 20 by calling generateRandom()
. How can I exclude some values, say 8 and 15?
function generateRandom(mi
I think it should be like this, if you want good distribution on all numbers. and, for this solution, it is required to higher max than 15 and lower min that 8
function generateRandom(min, max) {
var v = Math.floor(Math.random() * (max - min + 1 - 2)) + min;
if (v == 8) return max-1;
else if (v == 15) return max-2;
else return v;
}
var test = generateRandom(1, 20)