Example Output

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page
(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:

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 probablility and statistics course.

QUESTION 10:

Would you ever need a random floating point value?