Rolling a Six-Sided Die 6,000,000 Times
To show that the numbers produced by nextInt occur with approximately equal likelihood, let’s simulate 6,000,000 rolls of a die with the application in Fig. 6.7. Each integer from 1 to 6 should appear approximately 1,000,000 times.
Click here to view code image
1 // Fig. 6.7: RollDie.java 2 // Roll a six-sided die 6,000,000 times. 3 import java.security.SecureRandom; 4
5 public class RollDie 6 { 7 public static void main(String[] args) 8 { 9 // randomNumbers object will produce secure random numbers10 SecureRandom randomNumbers = new SecureRandom();11
12 int frequency1 = 0; // count of 1s rolled13 int frequency2 = 0; // count of 2s rolled14 ...