Java Program Random Number Generator

In this example, You learn about random number generator java.

Here you learn Java program for random number generator, You are given a year and the task of the program to generate random number by making instance of random class.

Random Number Generator in Java

import java.util.Random;
import java.util.Scanner;

public class RandomNumber {
    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        Random rand = new Random();

        System.out.print("Please enter maximum range: ");
        int maxRange = scanner.nextInt();

        for (int loop = 1; loop <= 10; loop++) {
            System.out.println(rand.nextInt(maxRange));
        }
        
    }
}
Output

  
 Please enter maximum range: 1000
 647
 394
 437
 634
 339
 981
 355
 614
 637
 801
You have any problem in the above random number generator Java. Do not hesitate and write your problem in the comment box. I will support your problem

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form