droll icon indicating copy to clipboard operation
droll copied to clipboard

Replace Math.random with uniform distributed random values

Open taekahn opened this issue 6 years ago • 0 comments

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.

taekahn avatar May 12 '18 17:05 taekahn