Created
February 19, 2013 12:34
-
-
Save hleinone/4985489 to your computer and use it in GitHub Desktop.
Poetic unicorn.
This file contains hidden or 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
import java.lang.reflect.Field; | |
import java.util.Random; | |
/** | |
* Unicorns may be betray'd with trees. | |
*/ | |
public class Unicorn { | |
private static boolean patted = false; | |
static { | |
try { | |
Field f = Math.class.getDeclaredField("randomNumberGenerator"); | |
f.setAccessible(true); | |
f.set(Math.class, new NonRandom()); | |
} catch (NoSuchFieldException | SecurityException | |
| IllegalArgumentException | IllegalAccessException e) { | |
System.out.println("Okay Random, you win"); | |
} | |
} | |
/** | |
* Now might I do it pat. | |
*/ | |
public static boolean pat() { | |
return patted = !patted; | |
} | |
/** | |
* Chance may crown me. | |
*/ | |
private static class NonRandom extends Random { | |
private static final long serialVersionUID = 1L; | |
/** | |
* Double, double toil and trouble. | |
*/ | |
@Override | |
public double nextDouble() { | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment