A number of you have written to ask me about the Practice icon on page 59 of Java eLearning Kit for Dummies. It turns out that the practice won’t quite work as originally written because Java’s Random class now ensures that you get a random number each time you call it. As a result, the original practice no longer works.
In order to obtain consistent results from the example, you would need to set the seed to the same value every time. Here is an example of what I mean:
Notice that I’ve commented out the original MyRandom.setSeed(MyCal.getTimeInMillis()); line that ensures you get a more random result every time and added a new MyRandom.setSeed(5); line that sets the seed to the same value every time. Now when you run the example, you get the same value every time. On my system, the example guesses 8 every time.
This change to the practice should produce the desired result. I’m sorry about any confusion the original practice may have causes. Please let me know about any other book-related concerns at [email protected].