Reputation: 65
1) In PHP when I use native php MT implementation
mt_srand(1);
var_dump(mt_rand());
var_dump(mt_rand());
var_dump(mt_rand());
I get values
1244335972
15217923
1546885062
2) In this Mersenne Twister implementation
http://kingfisher.nfshost.com/sw/twister/
I run
$twister = new twister(1);
var_dump($twister->int31());
var_dump($twister->int31());
var_dump($twister->int31());
and get
1791095845
2135392491
946286476
3) In JS I use
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/JAVASCRIPT/java-script.html
m = new MersenneTwister(1)
m.genrand_int31()
m.genrand_int31()
m.genrand_int31()
and get
895547922
2141438069
1546885062
How could it happens?
Actually, this in JS
m = new MersenneTwister(1)
m.genrand_int32()
1791095845
and this in PHP
$twister = new twister(1);
var_dump($twister->int32());
return the same value 1791095845, but only for the first call.
Upvotes: 1
Views: 1162
Reputation: 27752
The Mersenne twister is a class of PRNGs, not a single algorithm. The Mersenne primes used in the algorithm may vary, and different primes will produce different results for the same seeds.
Upvotes: 4