1 // Application to show random number generator 2 3 public class RollDice 4 { 5 public static void main (String[] args) 6 { 7 int face; 8 int frequency[]; 9 10 frequency = new int[6]; 11 12 /* Use random to generate real random numbers between 0 and 1, 13 and scale them to "faces" between 1 and 6 */ 14 15 for(int roll=1; roll <= 6000; roll++) 16 { face = 1 + (int) (Math.random() * 6); 17 ++frequency [face-1]; 18 } 19 20 // print results 21 22 System.out.println("\n" + "Face " + "Frequency"); 23 for (face = 0; face < frequency.length; face++) 24 System.out.println(String.valueOf(face+1) + " " 25 + String.valueOf(frequency[face])); 26 } 27 } 28