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.
pull/700/head
EmeraldBlock 4 years ago committed by GitHub
parent da9f91aca4
commit a79500d574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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;

Loading…
Cancel
Save