Unknown user Unknown user - 1 year ago 82
Java Question

Getting random numbers in Java

Possible Duplicate:

Java: generating random number in a range

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

How may I do that with the help of

How do I bound the values that Math.random() returns?

Answer Source
Random rand = new Random();

int  n = rand.nextInt(50) + 1;
//50 is the maximum and the 1 is our minimum 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download