generate random number
is this right..im trying to generate a random numbre between 1 and 1000.
public void theGame()
{
/* Write a statement that sets instance variable number to a random number
between 1 and 1000 */
Random generator = new Random();
int rn1 = rnd.nextInt(1) + 1000; // number in range 1..1000
} // end method theGame
[359 byte] By [
Lizanea] at [2007-11-27 7:42:44]

> is this right.
try it a couple of times. does it actually
> generate a random numbre
> between 1 and 1000.
?
> int rn1 = rnd.nextInt(1) + 1000; // number in
what range do the api docs for Random.nextInt(int) say it returns? so what range will "that + 1000" be?
in the future, please use code tags when posting code
http://java.sun.com/javase/6/docs/api/java/util/Random.html#nextInt(int)Also, your method create a new pseudorandom number generator every time it is called. It makes more sense to have this generator as a field instead of a local variable.