droll
droll copied to clipboard
Replace Math.random with uniform distributed random values
Problem:
Math.random produces uniformly distributed numbers within the range of (0, 1], but trying to map those values integer range with Math.floor(Math.random() * pieces.numSides)
leads to slightly biased results.
Solution:
Add a dependency on random-js.
random-js provides an interface that allows you to specify both the source (algorithm) of the random number generator and the desired distribution. In this case a uniform integer distribution over the range of 1 to pieces.numSides
.