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

alex nonya
PLUS
alex nonya
Courses Plus Student 9,265 Points

Random integer Module? Is there a module to import to simply ask for a random int between a start and stopping number?

This is such an inefficient way of generating random numbers, are there any modules that have created better methods?

I recently used Python3 to simply state randint(1, 10), which would give you a random integer between 1 and 10.

Why all the extra steps with Javascript?

Why don't you write a function like that, it's easy and then you can keep reusing it every time you need it.

1 Answer

Steven Parker
Steven Parker
221,328 Points

The random function for picking integers in range is a well-known (and well-documented) formula that is easily implemented. The course shows how to do it in a single line.

As Piotr suggested, if you think you might use it frequently, you can always create your own library of functions and include it.