From a79500d57442031802fda7fe1496635989a20fd1 Mon Sep 17 00:00:00 2001 From: EmeraldBlock <69981203+EmeraldBlock@users.noreply.github.com> Date: Thu, 8 Oct 2020 01:44:10 -0500 Subject: [PATCH] Fix non-uniform distribution for freeplay shape color palette (#789) * use nextIntRange instead of nextIntRangeInclusive * Remove nextIntRangeInclusive This function gave the minimum and maximum integer half as much weight, and it was not used anywhere except to generate a freeplay shape color palette, and that now uses nextIntRange. --- src/js/core/rng.js | 11 ----------- src/js/game/hub_goals.js | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/js/core/rng.js b/src/js/core/rng.js index 9c5c1c43..7a6766cd 100644 --- a/src/js/core/rng.js +++ b/src/js/core/rng.js @@ -108,17 +108,6 @@ export class RandomNumberGenerator { assert(max > min, "rng: max <= min"); return Math.floor(this.next() * (max - min) + min); } - /** - * @param {number} min - * @param {number} max - * @returns {number} Integer in range [min, max] - */ - nextIntRangeInclusive(min, max) { - assert(Number.isFinite(min), "Minimum is no integer"); - assert(Number.isFinite(max), "Maximum is no integer"); - assert(max > min, "rng: max <= min"); - return Math.round(this.next() * (max - min) + min); - } /** * @param {number} min diff --git a/src/js/game/hub_goals.js b/src/js/game/hub_goals.js index e7a1fea7..c9d9494f 100644 --- a/src/js/game/hub_goals.js +++ b/src/js/game/hub_goals.js @@ -369,7 +369,7 @@ export class HubGoals extends BasicSerializableObject { if (allowUncolored) { universalColors.push(enumColors.uncolored); } - const index = rng.nextIntRangeInclusive(0, colorWheel.length - 3); + const index = rng.nextIntRange(0, colorWheel.length - 2); const pickedColors = colorWheel.slice(index, index + 3); pickedColors.push(rng.choice(universalColors)); return pickedColors;