• Post Reply Bookmark Topic Watch Topic
  • New Topic

HELP!!! Im running out of time.  RSS feed

 
Martin Bezener
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my code:

Okay I posted here yesterday about a problem with random numbers coming out the same because the program runs to fast for the system clock to change. How can I incorporate the Thread.sleep method to slow it down? The problem area is highlighted.
BTW - this is a dummied down version of the Drunk Walk, or Random Walk where a random number is generated which will determine the way to walk. He starts in the middle and has 5 steps to each end, with only enough energy for 100 steps. The results I always get are:
-5
5(stepCount)
or
5
5 (stepCount)
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ November 27, 2003: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I've understood your inquiry correctly...
Perhaps something simple such as

inside of your while loop will do the trick.
 
Martin Bezener
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay that idea works.... somewhat. Occasionally it will tell me that the drunk man has taken either 7 or 13 steps, but then continues to only say that he took exactly 5 steps. This definitely helped, but is there anyway to fix this problem? My output looks like this
5
13 // good
-5
5 //BAD
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand your question. With the sleep statement, the program seems to me to do what you'd suggested you wanted it to do.
What are you trying to do? What does the code currently seem to be doing? What are your thoughts on what changes to make, and what have you tried?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!