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:
John Peacock
Date:
March 6, 2001 11:11
Subject:
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID:
3AA53592.194DA6D6@rowman.com
Tony Finch wrote:
> 
> >I agree that it does fit DWIM, but since rand() returns a float between
> >0 and 0.999999999, what would the corresponding integer range be:
> >0-10, 0-100, 0-1000???  I think this is one of those cases where the
> >user has to make that determination for themselves.
> 
> I suggest 0..1.
> 

I can see some utility for (the original code)

use integer;
for(;;) {
        print rand 10;
}

to return integers from 0..9, and it is even easy to create a patch
to do that.  The problem comes when someone codes this:

use integer;
for(;;) {
        print rand;
}

because this has no meaning.  The range of integers 0..1 is not 
as easily derivable from rand()'s 0..0.999999999 (you'd have to use
round).

Since 'use integer' strictly affects mathematic operations, not
mathematic functions, I think this is not a good enhancement.

John Peacock

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