From 7e231689139bfff5772a66e09f4885fbb80db950 Mon Sep 17 00:00:00 2001 From: Joke Book Date: Mon, 11 Mar 2019 21:56:58 +0000 Subject: [PATCH] Remove and fix comments --- src/util/math-util.js | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/src/util/math-util.js b/src/util/math-util.js index 70f9f6ed7..ce10073af 100644 --- a/src/util/math-util.js +++ b/src/util/math-util.js @@ -79,42 +79,20 @@ class MathUtil { } /** - * Return a random number given an inclusive range and a set - * of numbers that should be excluded. - * For instance, (1, 5, [2, 3]) will only pick 1, 4, or 5 (with equal + * Return a random number given an inclusive range and a number in that + * range that should be excluded. + * + * For instance, (1, 5, 3) will only pick 1, 2, 4, or 5 (with equal * probability) * * @param {number} lower - The lower bound (inlcusive) * @param {number} upper - The upper bound (inclusive), such that lower <= upper - * @param {number} exclude - The numbers to exclude (MUST be in the range) + * @param {number} exclude - The number to exclude (MUST be in the range) */ static inclusiveRandIntWithout(lower, upper, excluded) { - /** - * By excluding a random integer, we are lowering the number - * of possible options by one. - * - * The algorithm is to pick a random integer in the range - * [lower, upper-1]. If we accidentally pick the exlcuded number, - * we will instead pikc "upper". - * - * So if C is excluded, and we are picking A..F then: - * - * A B C D E (no F) - * = = = = = - * A B F D E - * - * In the event that our excluded number isn't in the range, we will never pick it, - * and so we don't need to worry about remapping it to something else. For example, - * if we want to exclude 'F': - * - * A B C D E (no F) - * = = = = = - * A B C D E - */ - - // Note that 5 - 3 = 2, but there are 3 options (3, 4, 5). - // As a result, there isn't a need to subtract 1 as we've - // already got one less than the size of the range. + // 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) const possibleOptions = upper - lower; const randInt = lower + Math.floor(Math.random() * possibleOptions);