Random no. in Java



random image icon


Hello friends, Welcome to programmingscoop. In this post you will learn how to take random no. in java program. 
Many times we have to use random no. means automatic generated no. from some specific range. for operating some operation.

Code:- 

For taking random numbers we have to import one module at the starting of program that is 

  1. //importing module
  2. import java.util.Random;     //used to take random value

Now create the object of Random class class and call rand method.

  1. /*  how to take random no. in java********/
  2.    
  3.      Random rand=new Random();
  4.         int number=rand.nextInt(50); 

This code will assign any no. between 0 to 49. you can change the parameter of rand.nextInt() method according to your program.
Read related post for learn more techniques.