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 14:13
Subject:
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID:
20010306221043.17830.qmail@foad.org
On Tue, Mar 06, 2001 at 02:08:02PM -0500, John Peacock wrote:
> 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.
> > 

For

    use integer;
    print rand;

I would expect the range to be 0 .. 0.

But for

    use integer;
    print rand (10);

I would expect the range to be 0 .. 9 inclusive.

> 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.

Could you please, from a mathematical viewpoint, tell me what the
difference is between an operator and a function? Even from a CS
standpoint, the only differences are syntactical details, only relevant
to parsing tables, and largely artificial.


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