mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -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) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue