The following Java code generates random numbers.
- import java.util.*;
- import java.util.Scanner;
- class Random
- {
- public static void main(String[] args)
- {
- int count, num, range;
- Scanner input = new Scanner(System. in );
- System.out.print("Enter how many random numbers you want: ");
- num = input.nextInt();
- System.out.print("Enter the max range of random number: ");
- range = input.nextInt();
- Random rnum = new Random();
-
-
-
- System.out.println(+num + " Random Numbers between 0 to " + range + " are as following:" + "\n");
- for (count = 1; count <= num; count++)
- {
- System.out.println(rnum.nextInt(range));
- }
- }
- }
Thank you, keep learning and sharing