Generate Random numbers not working
I am trying to generate a random number, but it is not working!!!
Please help
import java.util.Random;
class test2
{
publicstaticvoid main(String args[])
{
int rand;
rand = generator.nextInt(1) ;
System.out.println("Number is " + rand );
}
}
> it is not working!!!
"Not working" is defined as rabid monkey ninjas burning your flesh with hot pokers every time you run your application. If this isn't your problem then maybe you should be a bit more specific (e.g., providing an error message, etc.).
~
You need to give more information. What is the possible range of the random numbers you are looking for. nextInt(1) gives you 0 and only 0 if I am not mistaken. Also, where are you initializing your Random class variable? I don't see you declaring generator as a variable of Random, nor initializing it w/ the Random constructor.
> you never created a "generator" object.
Oh, sure. Take the easy way out. ;o)
~
Hippo, If your space bar doesnt work on Windows hold ALT and then
type 32 on the NUMPAD. Voila.
Or use the Windows GUI keyboard
start - all programs - accessories - accessibility - on screen keyboard