Getting random numbers in java

Total Post:117


 1480  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
  1. Re: Getting random numbers in java

    Hi Jayprakash!

    Try as following

    Random rand = new Random();

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


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.