Background: The other day hangon was looking for a way of Randomizing Large Integers. BrowserUk soundly suggested Math::Random::MT for the task. Although this is a perfectly good solution it was not viable due to restriction on compiled code. Having nothing better to do for a couple of hours I had a look at Math::Random::MT. After patching the header file so it would install on Win32 (should fix the compilation failures on Darwin too) I noted it would be easy enough to port to vanilla perl, and thus Math::Random::MT::Perl was born.

Like the other ::Perl modules it exists only to plug the gap when you can't install better/faster C/XS. Anyway after a bit of mucking around this pure Perl version of the Mersene Twister PRNG now exists on CPAN. On the 32 bit platforms I have access to it works fine (producing identical output to the C at an acceptable 100k PRNs/sec) however it breaks on 64 bit architecture. This occurs due to the need to 'use integer' in parts to get the correct integer wrap behaviour, but on 64 bit machines the wrap does not happen at 2**32-1, it happens at 2**64-1. As you can't directly specify a uint32_t within perl this presents a problem.

I think a patch like this:

{ use integer; $int = $int * $big_num; # need 32 bit int wrap here bu +t don't get on 64 bit arch $int >>= 32 if $int > 0xffffffff; # <-- add this line }

should fix the issue by constraining the 64 bit ints to 32 bits, effectively forcing the wrap. I can't test this as I don't have access to a 64 bit perl. While I know this won't break things on 32 bit arch I don't really want to upload it just to see if it works when a 64 bit tester runs it. There is modified module here. If anyone with a 64 bit perl has a moment could you run:

wget http://74.55.157.146/Math-Random-MT-Perl-1.02.tar.gz && \ tar -xzf Math-Random-MT-Perl-1.02.tar.gz && \ cd Math-Random-MT-Perl-1.02 && \ perl Makefile.PL && make test

With any luck it should come up with "All tests successful". If not the output would be helpful.

If it does run OK and you have a couple of minutes there is a little script in /t called validate.pl. You would need to actually install both Math::Random::MT and Math::Random::MT::Perl. A quick run of this does a lot more in depth testing to ensure that the C and Perl results are identical. A command line arg of 1000 will do 2 million comparison tests and should be over in under 20 seconds.


In reply to Help with x86_64 bit testing for CPAN module by tachyon-II

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.