go to previous page   go to home page   go to next page hear noise highlighting

Answer:

No. You can use one random number generator to simulate both dice. Use it once for one die, then again for the other.


Two-dice Gotcha!

In fact, if you use two random number generators, you need to be careful. The following code:

Random rand1 = new Random();
Random rand2 = new Random();

will most likely produce two random number generators which are initialized to the same seed. Each generator would then produce the same pseudorandom sequence. This is not what you want.

The reason this happens is because the constructor Random() creates a seed based on the current time in milliseconds. Time changes little between the execution of the two statements, so both random number generators might use the same seed. Two generators started with the same seed generate the same sequence of pseudorandom numbers. You could initialize the second random number generator using a random number from the first, but it is more convenient to use just one random number generator.


QUESTION 8:

Do you ever need more than one random number generator?


go to previous page   go to home page   go to next page