Last active
December 13, 2015 22:29
-
-
Save stuartwdouglas/4984419 to your computer and use it in GitHub Desktop.
Unicorn meat by horrible reflection hack
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 MagicLand { | |
static { | |
try { | |
Field field = Math.class.getDeclaredField("randomNumberGenerator"); | |
field.setAccessible(true); | |
field.set(null, new Random() { | |
@Override | |
public double nextDouble() { | |
return 0; | |
} | |
}); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static void main(String[] args) { | |
for (int i = 0; i < (Math.random() * 500) + 2; i++) { | |
if (Unicorn.pat()) { | |
System.out.println("UNICORN #1: PAT THIS UNICORN ONCE"); | |
} | |
} | |
for (int i = 0; i < (Math.random() * 500) + 2; i++) { | |
if (Unicorn.pat()) { | |
System.out.println("UNICORN #2: PAT THIS UNICORN ONCE"); | |
} | |
} | |
System.out.println("END OF PROGRAM"); | |
} | |
static class Unicorn { | |
static int count; | |
public static boolean pat() { | |
return ++count % 2 == 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment