C implementation of mersenne twister that produces results equal to mt_rand in PHP?

169 views Asked by At

I'm working on some apps, and need to validate some results of random number generation. I can do it in PHP, the same as the source app, but it's slow. We'd like to code the validator in C for speed. The issue is that every implementation of the MT algo in C produces different results than it does in PHP (using the same seed).

The big issue is the data from PHP has already been made, and has been database logged for over two months now - we cannot just change the generator in PHP (to a class that I know matches standard C results).

I believe it has to do with integer size and the signed/unsigned issue PHP has - our 32 bit implementation has the MAX_RAND at 2.147billion (or whatever the exact number is) while the same datatype in C is -2.147bil to 2.147 bil if signed, and 4.3bil if unsigned.

Is there a way to restrict the max integer size in C? Or does anyone know of an implementation where, using the same seed, we can produce the same results? I really don't want to do this in PHP - it's absurdly slow in comparison.

0

There are 0 answers