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:
rspier
Date:
March 5, 2001 13:03
Subject:
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID:
15011.65294.400692.855296@rls.cx
>>>>> "JP" == John Peacock <jpeacock@rowman.com> writes:
JP> I would like one of the mathematicians on the list to confirm that
JP> using floor like that will in fact yield a random list; I suspect
JP> that it won't.  In fact, that patch will return a list of zero's
JP> if the default rand() is called while "use integer" is in effect.

John-

    You are correct.  rand() with floor will always return zero.
Maybe it's better to use rint()... which will then either return 0 or
1. 

    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


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