102
Java Math.random() method
The java.lang.Math.random() is used to return a pseudorandom double type number greater than or equal to 0.0 and less than 1.0. The default random number always generated between 0 and 1.
If you want to specific range of values, you have to multiply the returned value with the magnitude of the range. For example, if you want to get the random number between 0 to 20, the resultant address has to be multiplied by 20 to get the desired result.
Syntax
Return
Example 1
Output:
0.2594036953954201 0.08875674000436018
Example 2
Output:
19.09244621979338 14.762266967495655
Example 3
Output:
21.30953881801222 29.762919341853877
Next TopicJava Math