No description, website, or topics provided.
JavaScript Java
Switch branches/tags
Nothing to show
Clone or download
Latest commit 9afc08a Apr 17, 2017
Permalink
Failed to load latest commit information.
node Add MWC1616 example Apr 16, 2017
README.md Add MWC1616 example Apr 16, 2017
ReplicatedRandom.java Initial commit. Sep 1, 2014
ReplicatedRandomTest.java Initial commit. Sep 1, 2014

README.md

Node (MWC1616)

See README in node folder

Java (LCG)

Given a double generated from nextDouble of a java.util.Random, recreate a Random with the same state. This ReplicatedRandom can then be used to predict the future values of the original Random.

Example:

Random r = new Random();
ReplicatedRandom rr = new ReplicatedRandom();
rr.replicateState(r.nextDouble());
System.out.println(r.nextDouble() == rr.nextDouble()); // True
System.out.println(r.nextDouble() == rr.nextDouble()); // True
System.out.println(r.nextDouble() == rr.nextDouble()); // True

Also works with Math.random() since it uses Random internally:

ReplicatedRandom rr = new ReplicatedRandom();
rr.replicateState(Math.random());
System.out.println(Math.random() == rr.nextDouble()); // True
System.out.println(Math.random() == rr.nextDouble()); // True
System.out.println(Math.random() == rr.nextDouble()); // True

Also works for nextInt() but requires two consecutive values:

Random r = new Random();
ReplicatedRandom rr = new ReplicatedRandom();
rr.replicateState(r.nextInt(), r.nextInt());
System.out.println(r.nextInt() == rr.nextInt()); // True
System.out.println(r.nextInt() == rr.nextInt()); // True
System.out.println(r.nextInt() == rr.nextInt()); // True

See this blog post for details.