New course! Every coder should learn Generative AI!
Try a free lesson0
How can I get a random number in Java?
2 Answers
+ 1
For generating random numbers within a range using Math.random(), follow the steps below:
Declare the minimum value of the range
Declare the maximum value of the range
Use the formula Math.floor(Math.random()*(max-min+1)+min) to generate values with the min and the max value inclusive.