How can I get a random number in Java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I get a random number in Java?

10th Dec 2022, 9:58 PM
Gendy
Gendy - avatar
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.
10th Dec 2022, 10:06 PM
Knight
Knight - avatar