Skip to content

Instantly share code, notes, and snippets.

@hleinone
Created February 19, 2013 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hleinone/4985489 to your computer and use it in GitHub Desktop.
Save hleinone/4985489 to your computer and use it in GitHub Desktop.
Poetic unicorn.
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