Toby Ewing wrote:
I've been working with the Mersenne Twister random number generator for a while. I translated it from the original C to Pascal several years ago, and the GPC team incorporated it into the GPC unit. But since then the original authors have found and fixed a bug in their initilization procedures, and other users have suggested various speedups.
I've now updated my original translation, validated it against the authors' test output, performed some other minor tests, and done what small optimizations I know how to do. Source for the unit and a test program are appended below.
I've briefly looked at your code, and it seems there are some off-by-one errors, e.g.:
for kk := mtN-mtM to mtN-1 do begin
(where the C version says `<N-1'). I think there are more.
Also, if you'd like to have this code included with GPC, it would be good to use the same coding style and interfaces (including function names such as `Default_RandInt' which are called through pointers in the RTS). I don't have the time to do the reformatting myself now. It would also make it easier for me to see what's actually changed. I remember having updated the initalization, apparently corresponding to the "2002/01/09" changes. I don't know if anything significant was changed after that.
Frank