Skip to content

Instantly share code, notes, and snippets.

@JonathanLalou
Created April 30, 2013 14:37
Show Gist options
  • Save JonathanLalou/5489151 to your computer and use it in GitHub Desktop.
Save JonathanLalou/5489151 to your computer and use it in GitHub Desktop.
@Test
public void testLLN() {
final Random random = new Random();
for (int j = 4; j >= 2; j--) {
int tries = Integer.MAX_VALUE / (int) (Math.pow(10.0, j));
int equalsEight = 0;
Integer x;
for (int i = 0; i < tries; i++) {
x = random.nextInt(6);
if (x == 5) {
equalsEight++;
}
}
double actualMean = (double) equalsEight / tries;
double theoricalMean = 1.0 / 6.0;
double deviation = 100 * (1 - actualMean / theoricalMean);
System.out.println("**** Test with Integer.MAX_VALUE / 10^" + j);
System.out.println(" Actual Mean: " + actualMean);
System.out.println("Theorical Mean: " + theoricalMean);
System.out.println("Deviation: " + Double.toString(deviation).substring(0, 8) + "%");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment