Created
August 25, 2015 14:35
-
-
Save tommcdo/795987effb775f3cf05a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Random { | |
public static void randomlyThrow() throws Exception { | |
if (Math.random() < 0.25) { | |
throw new Exception("Random!"); | |
} | |
} | |
public static void main(String[] args) { | |
int failures = 0; | |
for (int i = 0; i < 1000; i++) { | |
int throwCount = 0; | |
for (int j = 0; j < 11; j++) { | |
try { | |
randomlyThrow(); | |
} catch (Exception e) { | |
throwCount++; | |
} | |
} | |
if (throwCount < 2) { | |
failures++; | |
} | |
} | |
System.out.println("Failed " + failures + " times"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment