develooper Front page | perl.perl5.porters | Postings from March 2001

Re: [ID 20010305.005] "use integer" doesn't make rand() return integers

Thread Previous | Thread Next
March 6, 2001 00:48
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID:
On Mon, Mar 05, 2001 at 04:08:16PM -0500, John Peacock wrote:
> Robert Spier wrote:
> > 
> > >>>>> "JP" == John Peacock <> writes:
> >     BUT - to be consistent with the current behaviour of use integer:
> > perl -Minteger -le 'print 0+rand' # rinse and repeat
> >     it is fine for it always to answer 0.  if you want bigger (random)
> > integers, you must specify that.
> > 
> >     But I don't think the patch should be integrated anyway.  That's
> > not what use integer is for.
> > 
> > -R
> I agree that the patch should not go in; my point was I'm not even
> sure that int(rand(10)) will not bias the random sequence returned by
> rand().  When dealing with random numbers, I know enough to know only 
> that I don't know enough!  ;~)

Well, if it doesn't than rand() is having a problem; and that doesn't
have anything to do with 'use integer' or not. After all, if you cannot
expect int(rand(10)) not to give 10% 0s, 10% 1s, .. 10% 9s, the values
it returns are not uniformely distributed.

Having said that, having 'rand' returning integers when 'use integer'
is in effect fits exactly in Perls DWIM nature.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About