Unknown user Unknown user - 7 months ago 46
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?

Random rand = new Random();

int  n = rand.nextInt(50) + 1;
//50 is the maximum and the 1 is our minimum