Skip to main content
Post Undeleted by Unihedron
Post Deleted by Unihedron
added 13 characters in body
Source Link
Unihedron
  • 1.3k
  • 14
  • 22

Java

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 */ } } 

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 */ } } 

Java

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 */ } } 
Source Link
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 */ } }