Java program to generate random numbers

Java Programming Java8Java Technologies Object Oriented Programming

The java.util.Random class instance is used to generate a stream of pseudorandom numbers.

  • The class uses a 48-bit seed, which is modified using a linear congruential formula.
  • The algorithms implemented by class Random use a protected utility method that on each invocation can supply up to 32 pseudo randomly generated bits.
  • The nextInt() method of this class is used to get the next pseudorandom, uniformly distributed int value from this random number generator's sequence.


import java.util.*;
public class RandomNumberGeneration {
   public static void main( String args[] ) {
      // create random object
      Random randomno = new Random();
      Scanner sc = new Scanner(;
      System.out.println("How many random numbers do you need :");
      int n= sc.nextInt();
      // check next int value
      for(int i=0; i<n; i++){


How many random numbers do you need :

Published on 25-Apr-2018 17:10:55