Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with use of Math.Random() #110

Open
stendardo opened this issue Nov 27, 2021 · 0 comments
Open

Bug with use of Math.Random() #110

stendardo opened this issue Nov 27, 2021 · 0 comments

Comments

@stendardo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant