Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
221,451 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 :)