JS Random
Math.random() returns a random number between 0 and 1.
Math.random() returns a random number between 0 (inclusive), and 1 (exclusive).
Math.random()
Math.random() always returns a number lower than 1.
Preview
JavaScript Random Integers
Math.random() used with Math.floor() can be used to return random integers.
Preview
By multiplying Math.random() with 10, the result is between 0 and 9.9999. Then, Math.floor() rounds it down to the nearest integer.
Preview
A Proper Random Function
As you can see from the examples above, it might be a good idea to create a proper random function to use for all random integer purposes.
This JavaScript function always returns a random number between min (included) and max (excluded):
Preview