Home > DeveloperSection > Forums > Getting random numbers in java
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    May-07-2013 12:51 AM

 Java Java 
Ratings:


 1 Reply(s)
 792  View(s)
Rate this:
Hello Guys,

I would like to get a random value between 1 to 50.

How may I do that with the help of Math.random(); in Java?

Is there any way to bound the values that will be accepted?

Thank you


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-07-2013 7:50 AM

Hi Jayprakash!

Try as following

Random rand = new Random();

int  n = rand.nextInt(50) + 1;


Don't want to miss updates? Please click the below button!

Follow MindStick