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;
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;
2
3class scratch{
4 public static void main(String[] args) {
5 Random rand = new Random();
6 System.out.println( rand.nextInt(5) );
7 //prints a random Int between 0 - 4 (including 0 & 4);
8 }
9}
1import java.lang.Math;
2
3int randomNumber;
4
5int minimum = 1;
6int maximum = 10 - minimum;
7
8randomNumber = (int)((Math.random()*maximum) + minimum);
9
10System.out.println("Random Number (Between 1-10): " + randomNumber);