... (counter % 5 == 0) {
19              System.out.println();
20           }
21        }
22     }
23 }
1  5  3  6  2
5  2  6  5  2
4  4  4  2  6
3  1  6  2  2
6  5  4  2  6
1  2  5  1  3
6  3  2  2  1
6  4  2  6  4

Shifted and scaled random integers.

Rolling a Six-Sided Die 60,000,000 Times

To show that the numbers produced by nextInt occur with approximately equal likelihood, let’s simulate 60,000,000 rolls of a die with the application in Fig. 6.7. Each integer from 1 to 6 should appear approximately 10,000,000 times. Note in line 18 that we used the _ digit separator to make the int value 60_000_000 more readable. Recall that you cannot separate digits with commas. For example, if you replace the int value 60_000_000 with 60,000,000, the JDK 8 compiler generates several compilation errors throughout the for

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.