v1.3.0: improved how the game handles seeds and PRNG internally

This commit is contained in:
Evan Debenham
2022-04-26 16:00:37 -04:00
parent ede0439ab8
commit 23fd824789
6 changed files with 26 additions and 7 deletions

View File

@@ -49,7 +49,20 @@ public class Random {
}
public static synchronized void pushGenerator( long seed ){
generators.push( new java.util.Random( seed ) );
generators.push( new java.util.Random( scrambleSeed(seed) ) );
}
//scrambles a given seed, this helps eliminate patterns between the outputs of similar seeds
//Algorithm used is MX3 by Jon Maiga (jonkagstrom.com), CC0 license.
private static synchronized long scrambleSeed( long seed ){
seed ^= seed >>> 32;
seed *= 0xbea225f9eb34556dL;
seed ^= seed >>> 29;
seed *= 0xbea225f9eb34556dL;
seed ^= seed >>> 32;
seed *= 0xbea225f9eb34556dL;
seed ^= seed >>> 29;
return seed;
}
public static synchronized void popGenerator(){