go to previous page   go to home page   go to next page hear noise highlighting
(rand.nextInt(11)+2)

Answer:

No. The range is the same as with two dice, 2 through 12, but each of those outcomes is equally likely, unlike the case with two dice.


Example Output

Here is a sample run of the above (correct) program. (The user killed the program with control-C.)

You toss a 11
You toss a 8
You toss a 6
You toss a 5
You toss a 5
You toss a 5
You toss a 6
You toss a 6
You toss a 6
You toss a 12
You toss a 4
You toss a 5 Exception in thread "main" . . .

Here is a sample run of a program that (incorrectly) uses (rand.nextInt(11)+2):

You toss a 6
You toss a 10
You toss a 11
You toss a 4
You toss a 6
You toss a 5
You toss a 11
You toss a 9
You toss a 7
You toss a 2
You toss a 4
You toss a 3 Exception in thread "main" . . .

With such a small sample, you can't tell for sure that something is wrong. But you might be suspicious. To confirm your suspicions, gather much more data, then count the number of times each outcome occurs and check that the results match what you expect. This is part of what is studied in a probability and statistics course.


QUESTION 10:

Would you ever need a random floating point value?


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