zarocknz/javascript-winwheel

Bug with use of Math.Random()

stendardo opened this issue · 0 comments

Hi, looking at your code I noticed the line:
this.animation._stopAngle = Math.floor((Math.random() * 359));

According to the definition of Math.random() (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)

The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range.

So that line of code is actually "Generate a random integer number between 0 and 358" instead of between 0 and 359, which is what should be expected given the semantics of the code.

The line of code should be changed to:

this.animation._stopAngle = Math.floor((Math.random() * 360));