Java Math.random() methodThe 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. SyntaxReturnExample 1Test it NowOutput: 0.2594036953954201 0.08875674000436018 Example 2Test it NowOutput: 19.09244621979338 14.762266967495655 Example 3Test it NowOutput: 21.30953881801222 29.762919341853877 Next TopicJava Math |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India