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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with x86_64 bit testing for CPAN module
by almut (Canon) on May 22, 2008 at 13:27 UTC | |
by tachyon-II (Chaplain) on May 22, 2008 at 14:19 UTC | |
by almut (Canon) on May 22, 2008 at 14:55 UTC | |
|
Re: Help with x86_64 bit testing for CPAN module
by almut (Canon) on May 22, 2008 at 18:23 UTC | |
by tachyon-II (Chaplain) on May 22, 2008 at 23:59 UTC | |
|
Re: Help with x86_64 bit testing for CPAN module
by moritz (Cardinal) on May 22, 2008 at 12:59 UTC | |
|
Re: Help with x86_64 bit testing for CPAN module
by DrHyde (Prior) on May 28, 2008 at 10:27 UTC | |
by tachyon-II (Chaplain) on May 28, 2008 at 16:39 UTC |