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
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.util.Random();
2Random <name> = new Random();
3<variable> = <name>.nextInt(<excuslive top limit>);
1import java.util.Random;
2public class Example {
3 public static void main(String[] args) {
4 Random rd = new Random(); // creating Random object
5 System.out.println(rd.nextFloat()); // displaying a random float value between 0.0 and 1.0
6 }
7}