Java Reference
In-Depth Information
> 6 * Math.random();
<< 4.580981240354013
If we want to generate a random integer, we can use the Math.floor() method that we
saw earlier to remove the decimal part of the return value. The following code generates a
random integer between 0 and 5 (it will never be 6, because it always rounds down):
> Math.floor(6 * Math.random());
<< 4
It's a useful exercise to try and write a function that will generate a random number
between two values.
Experimental Methods
There are some experimental functions being considered for inclusion in the next version
of the ECMAScript specification and are already implemented in some browsers. You can
find a full list at the Mozilla Developer Reference.
Search WWH ::

Custom Search