1import java.util.Random;
2
3Random rand = new Random();
4
5// Obtain a number between [0 - 49].
6int n = rand.nextInt(50);
7
8// Add 1 to the result to get a number from the required range
9// (i.e., [1 - 50]).
10n += 1;
1import java.util.Random;
2
3Random rand = new Random();
4int random_integer = rand.nextInt(upperbound-lowerbound) + lowerbound;
1/* First Method */
2int random = (int) (Math.random() * 100 + 1); /* Random number between 1 and 100*/
3int random = (int) (Math.random() * 65 + 1); /* Random number between 1 and 65*/
4/* Second Method */
5import java.util.Random;
6Random randnumber = new Random();
7int number = randnumber.nextInt(100); /* between 1 and 100*/
8system.out.println(number);
1public int getRandomNumber(int min, int max) {
2 return (int) ((Math.random() * (max - min)) + min);
3}