Created
January 14, 2010 10:47
-
-
Save oupo/277071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calc_trainer_id_by_seed(seed) { | |
var mt0 = seed >>> 0; | |
var mt1 = mul(1812433253, mt0 ^ (mt0 >>> 30)) + 1; | |
var mt2 = mul(1812433253, mt1 ^ (mt1 >>> 30)) + 2; | |
var mt_last = mt2; | |
for (var i = 3; i <= 398; i++) { | |
mt_last = mul(1812433253, mt_last ^ (mt_last >>> 30)) + i; | |
} | |
var value; | |
value = (mt1 & 0x80000000) | (mt2 & 0x7fffffff); | |
value = mt_last ^ (value >>> 1) ^ ((value & 1) ? 0x9908b0df : 0); | |
value ^= value >>> 11; | |
value ^= (value << 7) & 0x9d2c5680; | |
value ^= (value << 15) & 0xefc60000; | |
value ^= value >>> 18; | |
return value >>> 0; | |
} | |
function mul(a, b) { | |
var a1 = a >>> 16, a2 = a & 0xffff; | |
var b1 = b >>> 16, b2 = b & 0xffff; | |
return (((a1 * b2 + a2 * b1) << 16) + a2 * b2) >>> 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment