Switch algorithm to map most things to +1

This commit is contained in:
Joke Book 2019-03-11 22:01:11 +00:00
parent 7e23168913
commit 7e2012c805
No known key found for this signature in database
GPG key ID: FE1A37AA1630F6EF

View file

@ -92,16 +92,13 @@ class MathUtil {
static inclusiveRandIntWithout(lower, upper, excluded) {
// Note that subtraction is the number of items in the
// inclusive range [lower, upper] minus 1 already
// (e.g. in the set {3, 4, 5}, 5 - 3 = 2)
// (e.g. in the set {3, 4, 5}, 5 - 3 = 2).
const possibleOptions = upper - lower;
const randInt = lower + Math.floor(Math.random() * possibleOptions);
if (randInt === excluded) {
// We've picked the excluded number.
return upper;
if (randInt >= excluded) {
return randInt + 1;
} else {
// We haven't picked the excluded number, so this
// value maps to itself.
return randInt;
}
}