0

Random Int in java

random.nextInt( max - min + 1 ) + min max = 5 min = 1 picks a number(4,3,2,1)? (Bc max is exclusive?) So why not: random.nextInt( max - min) But what's the purpose of +1 and +min? I found some threads about the topic, but I don't get it.

13th Oct 2020, 6:22 PM
Fu Foy
Fu Foy - avatar
2 ответов
+ 2
You must show the complete code to answer the question properly. (max - min + 1) = 5 - 1 +1 = 5 So the number would be between 0 to 5 and 5 is exclusive. The "+min" is just adding one to the resultant and it's use is unknown.
13th Oct 2020, 7:13 PM
Avinesh
Avinesh - avatar
0
Thank you!
14th Oct 2020, 7:50 AM
Fu Foy
Fu Foy - avatar