Friday, January 20, 2017

Generate Random Numbers in Java

Tags

Random numbers are generated with the help of object of Random class.We call the functions in random class with this object which return random numbers

Following will help you understand:

import java.util.*;
public class Gndec
{
    public static void main(String[] args)
    {
       Random num=new Random();     //num object of Random class
       for(int i=1;i<6;i++)
       {
           System.out.println(num.nextInt(300));   //for integet values between 0 and 300
       }
    }
   
}


Output: