java.util.Random class  | Java Tutorials

This Java Tutorials “java.util.Random class” page providing clearly how to generate Random integer numbers in java application using Random class pre defined functionality.


 

Random class:

  • Available in java.util package.
  • Since jdk 1.0
  • Used to get System generated random numbers.
  • While creating “Scanner-class” object, we must specify “InputStream”.
  • But while creating “Random-class” object, no need to specify any “Input” source, because System will generate random numbers.

 

Program to generate Random number in integer limits:

 

We can generate Random integers with in the range using following method of Random class.

 

Program to generate Random integer number with in the given range:

 

Share this