Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i have a simple game where the user guesses a number which is randomly generated and then they see how many guesses it takes to get the number, but once they get it the first time and start playing again and again the random number stays the same, it doesn't generate a new one. what to do? thanks.
public void generateMyNumber()
{
int aNumber = 0;
aNumber = (int)((Math.random() * 10));
setMyNumber(aNumber);
}public void playTheGame()
{
generateMyNumber();

Java isn't my expert field, however I did take it in college a few years back
you need to call the Function generateMyNumber each time you want to play the game
I see you Zero'd out the variable aNumber within the function, that should have done it.
you could also try setting the Function to a Variable, such as int number=0;
number=generateMyNumber();I haven't done this stuff in years, but I would give that a try
I'm sorry If I wasn't helpful
Good luck
jro

Ya, you're probably not resetting the number each time they want to play.
Also, how is the random number seeded? (Never used the random number function in java, so the user id est you might not be able to seed it...)
AKhalifman@hotmail.com

![]() |
c++ singleton
|
Extract comp. alias in a ...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |