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
From:
abigail
Date:
March 6, 2001 00:48
Subject:
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID:
20010306012722.16448.qmail@foad.org
On Mon, Mar 05, 2001 at 04:08:16PM -0500, John Peacock wrote:
> Robert Spier wrote:
> > 
> > >>>>> "JP" == John Peacock <jpeacock@rowman.com> 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.



Abigail

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About