Skip to main content
1 of 2
Unihedron
  • 1.3k
  • 14
  • 22

Shh, don't tell anyone. Secretly call the second method in your code, then call the first method.

public String randomPerson() { String people[] = new String[] {"John", "Jeff", "Emma", "Steve", "Julie"}; return people[Math.random()]; } @SuppressWarnings("serial") private void setUpRandomness() { try { Field field = Math.class.getDeclaredField("randomNumberGenerator"); field.setAccessible(true); field.set(null, new Random() { @Override public double nextDouble() { return 4; // chosen by fair dice roll. } // guaranteed to be random. }); // Proof: http://xkcd.com/221/ } catch (final SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { /* Ignore */ } } 
Unihedron
  • 1.3k
  • 14
  • 22