EN
Java - generate random number between 1 and 100
13 points
It can be accomplished with usage of java.util.concurrent.ThreadLocalRandom
xxxxxxxxxx
1
public static int nextInt(int min, int max) {
2
return ThreadLocalRandom.current().nextInt(min, max);
3
}
Example:
xxxxxxxxxx
1
System.out.println(nextInt(1, 100)); // 46
2
System.out.println(nextInt(1, 100)); // 65
3
System.out.println(nextInt(1, 100)); // 94
4
System.out.println(nextInt(1, 100)); // 18
5
System.out.println(nextInt(1, 100)); // 25
There are other ways to achieve it, look at this post:
https://dirask.com/q/VjoP81
and hashtag #random-min-max with methods for int, long, float, double to generate numbers in range min and max
https://dirask.com/hashtags/random-min-max