mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Switch algorithm to map most things to +1
This commit is contained in:
parent
7e23168913
commit
7e2012c805
1 changed files with 3 additions and 6 deletions
|
@ -92,16 +92,13 @@ class MathUtil {
|
||||||
static inclusiveRandIntWithout(lower, upper, excluded) {
|
static inclusiveRandIntWithout(lower, upper, excluded) {
|
||||||
// Note that subtraction is the number of items in the
|
// Note that subtraction is the number of items in the
|
||||||
// inclusive range [lower, upper] minus 1 already
|
// 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 possibleOptions = upper - lower;
|
||||||
|
|
||||||
const randInt = lower + Math.floor(Math.random() * possibleOptions);
|
const randInt = lower + Math.floor(Math.random() * possibleOptions);
|
||||||
if (randInt === excluded) {
|
if (randInt >= excluded) {
|
||||||
// We've picked the excluded number.
|
return randInt + 1;
|
||||||
return upper;
|
|
||||||
} else {
|
} else {
|
||||||
// We haven't picked the excluded number, so this
|
|
||||||
// value maps to itself.
|
|
||||||
return randInt;
|
return randInt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue