+ 1
How to use the Random util?
I went searching for examples and i found this one: import java.util.Random; public class RandInt { public static void main(String[] args) { //define the range int min = 1; int max = 100; Random r = new Random(); int num = r.nextInt((max - min) + 1) + min; System.out.println(num); } } explanation please?
1 Réponse
+ 2
The nextInt, this method call returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive). This means that you will get numbers from 0 to 100 in your case. So you've done everything correctly by adding "1" to that number. Now range is from 1 to 100.