Dice { public int roll(){ return roll(iTimes, iFaces) + iModifier; } Dice();  Dice(int faces);  Dice(int times, int faces);  Dice(int times, int faces, int modifier); int getFaces(); void setFaces(int iFac); int getTimes(); void setTimes(int iTim); int getModifier(); void setModifier(int iModifier); int roll(); static int openRoll(); static int roll(int faces); static int roll(int times, int faces); static int random(int min, int max); @Override String toString();  }
@Test public void testBalance() { int faces = 20; int rolls = 10000000; int[] results = new int[faces]; for (int i=0; i<rolls; i++) { results[Dice.roll(faces)-1]++; } int max=results[0]; int min=max; int total = 0; int diff; int maxDiff = 0; int maxDiffIndex = 0; int expected = rolls / faces; double tolerance = Math.sqrt((double)rolls / 2); for (int i = 0; i < faces; i++) { total += (results[i] * (i + 1)); if (max < results[i]) { max = results[i]; } if (min > results[i]) { min = results[i]; } diff = Math.abs(results[i] - expected); if (diff > maxDiff) { maxDiff = diff; maxDiffIndex = i; } System.out.print(i+1); System.out.print("\t:"); System.out.print(results[i]); System.out.print(" "); System.out.print(diff); System.out.println(); assertEquals("Unbalanced result for " + (i + 1), expected, results[i], tolerance); } System.out.println(); System.out.println("max:\t" + max); System.out.println("min:\t" + min); System.out.println("avg:\t" + ((double)total / rolls)); }