Skip to content

Instantly share code, notes, and snippets.

@tommcdo
Created August 25, 2015 14:35
Show Gist options
  • Save tommcdo/795987effb775f3cf05a to your computer and use it in GitHub Desktop.
Save tommcdo/795987effb775f3cf05a to your computer and use it in GitHub Desktop.
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