Skip Menu |

This queue is for tickets about the Math-Random-MT CPAN distribution.

Report information
The Basics
Id: 78200
Status: resolved
Priority: 0/
Queue: Math-Random-MT

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.15
Fixed in: (no value)



Subject: rand() not taking parameter
perl -E 'use Math::Random::MT; for (1..1000) { say Math::Random::MT->new->rand(42) }' outputs: 0.704489288851619 0.409981292439625 0.981892759678885 0.418028630083427 0.507072699256241 0.116385537665337 0.872571577085182 0.223365942714736 0.478250751039013 0.696414319332689 0.597476160852239 0.981776786036789 ... I'd expect the numbers to be between 0 and 42. This is on perl 5.14.2, OSX 10.7.4
Le Mer 04 Jui 2012 08:49:39, david.morel@amakuru.net a écrit : Show quoted text
> perl -E 'use Math::Random::MT; for (1..1000) { say Math::Random::MT-
> >new->rand(42) }'
> > outputs: > > 0.704489288851619 > ... > > I'd expect the numbers to be between 0 and 42. >
Looking at the source code, not only does rand() ignore its $N parameter, but also irand()wrongly takes a $N parameter. So if you call irand($big_number), chances are that you will end up with a multiplication over the capacity of an int32. Seems to me that the multiplication is just in the wrong function.
Thank you both for your input. This issue is due to changes made in version 1.15 and was unfortunately not caught by the test suite. All should be fixed in version 1.16. Best, Florent