1

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.

2
  • Am I missing something? Are you asking why a random number generator is generating random numbers? Commented Apr 15, 2013 at 17:46
  • Ah, ok I did miss that. D'oh. Commented Apr 16, 2013 at 10:41

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

So then how can I get equal values for same given seeds on client and on server? Am I should implement MT algo myself?
Pretty much. Fortunately, it's not that hard.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.