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.
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.
0
Thank you!