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 maxNumber = 10;
5
6int randomNumber = rand.nextInt(maxNumber) + 1;
7
8System.out.println(randomNumber);
1import java.util.Random();
2Random <name> = new Random();
3<variable> = <name>.nextInt(<excuslive top limit>);
1public static int[] numbers()
2{
3int[] arr={5,6,7,8,9}; //initializing array
4return arr;
5}