Skip to main content
gamedev.net
🔒 Locked

Java Random Numbers

Started by Jama98 0 replies 350+ views
Original Post
Jama98
Jama98
My Program compiles but I keep on getting a Illegal Argument Exception: n must be positive. randomgenerator is a instance variable of the current class (WordArray). Code snippet below: public String randomWord() { int rand; // random number String str = new String(); rand = randgenerator.nextInt(num); // A random number is assigned to the variable rand str = getWord(rand).getSpell(); // str holds the spelling of a psuedorandom word return str; }
Zahlman
Zahlman
Well, it's pretty much telling you exactly what it doesn't like at runtime: the value you're passing in to nextInt isn't positive, and it needs to be. Where are you getting the number from? It appears to be another member variable, since it isn't declared here. Has it been set properly, or at all?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.