in reply to Help with x86_64 bit testing for CPAN module

my $xor = $mt[$i-1]^($mt[$i-1]>>30); { use integer; $mt[$i] = 1812433253 * $xor + $i; $mt[$i] >>= +32 if $mt[$i] > 0xffffffff }

It seems to work (at least this part), if you replace

$mt[$i] >>= 32 if $mt[$i] > 0xffffffff;

with

$mt[$i] &= 0xffffffff;

in mt_init_seed(), i.e. simply truncate the higher bits. In any case I then get the same init number sequence as with the Math::Random::MT C version.

Update: and if I replace the other 3 occurrences of the same pattern in mt_setup_array(), too, it does in fact pass all five tests...

Replies are listed 'Best First'.
Re^2: Help with x86_64 bit testing for CPAN module
by tachyon-II (Chaplain) on May 22, 2008 at 23:59 UTC

    Doh. How stupid do I feel now you point out the blindingly obvious! Of course we just want the low order bits for the wrap as you point out. To make it even worse there is already and seed & 0xffffffff immdediately above and this was my first thought of how to do it. I rejected it due to temporary insanity.

    Many thanks. The sawtooth pattern was pretty, and predictable given what I was doing.

    Cheers

    James