Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Fix the distribution of Options.Range.triangular()
The original implementation was converting a continuous distribution of [a, b] to integers by rounding, but this results in the smallest and largest integers having half as many float values that round to them compared to other integers in the range. For example, given the continuous range [0, 3]: 0.0 <= x < 0.5 rounds to 0 -> width of 0.5 0.5 <= x < 1.5 rounds to 1 -> width of 1.0 1.5 <= x < 2.5 rounds to 2 -> width of 1.0 2.5 <= x <= 3.0 rounds to 3 -> width of 0.5 (kind of plus an infinitesimal bit extra) To convert to 4 integers uniformly given a uniform continuous distribution, the width of the continuous distribution would have to be 4, e.g [-0.5, 3.5] or [0, 4]. This patch fixes the distribution of Options.Range.triangular() by increasing the width of the continuous distribution by 1. This requires adjusting the mode (`tri`) of the distribution to the new width of the distribution and accounting for the near zero chance of `random.triangular(a, b+1, adjusted_tri)` returning exactly `b+1`.
- Loading branch information