Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Random Number Challenge, Part II Solution

Is this random number function a 100% random?

Or are there values that are more likely than other?

1 Answer

Steven Parker
Steven Parker
231,236 Points

This might vary between different JavaScript engines, but some testing I did years ago showed that it was a very good simulation of random (we know it's only pseudo-random). The only thing I was unable to confirm is that in theory, the generated number can possibly be zero; but in millions of samples I never got an actual zero value.

For fun and extra practice, you might run some statistics yourself. If you do, be sure to update us on the results.

Happy coding!

Thanks Steven, very helpful :)