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 5, 2001 13:03
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID:
>>>>> "JP" == John Peacock <> 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.


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

    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. 


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