Languages
[Edit]
EN

Java - generate random number between 1 and 100

13 points
Created by:
JustMike
3488

Generate random number between 1 and 100 in Java 

It can be accomplished with usage of
java.util.concurrent.ThreadLocalRandom

public static int nextInt(int min, int max) {
	return ThreadLocalRandom.current().nextInt(min, max);
}

Example:

System.out.println(nextInt(1, 100)); // 46
System.out.println(nextInt(1, 100)); // 65
System.out.println(nextInt(1, 100)); // 94
System.out.println(nextInt(1, 100)); // 18
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

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.