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 7, 2001 16:32
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID:
On Wed, Mar 07, 2001 at 07:10:17PM -0500, Bryan C. Warnock wrote:
> > 
> > The following will never terminate for instance:
> > 
> >     {   use integer;
> >         print ++ $i, "\n";
> >         redo unless rand () > 0.1
> >     }
> Yes, I don't recall perl actually preventing the user from doing things 
> that are perfectly legit, but don't make any sense.  However, even with 
> 'use integer' semantics the above wouldn't terminate, so I don't see your 
> point.  Unless it returns an arbitrary range of integers.  What range 
> should that be?

The point isn't that rand() without arguments makes sense when floored
because of "use integer". My point is that not flooring rand() without
parameters in "use integer" context isn't very useful either, because
as soon as you use it any arithmetic context, the value becomes 0 anyway,
as demonstrated by the example above.
[The point was being made that if you floor the return value of rand()
 in use integer context, rand (1) (equivalent with calling rand() without
 arguments) would always return 0]

> (I've just reread your past posts.  It seems I misinterpreted your 
> position.  You want rand() of all sorts overloaded, no?  If so, I apologize 
> for my misrepresentation before.)

I don't want rand() to do anything in particular. I just don't like to
see the idea of 'rand() (for some people: that's with *OR* without an
argument, both cases for the price of one!) flooring to an integer in
"use integer" context' being ridiculed.

Close-mindedness doesn't bring us anything. And rand(10) returning integers
0 .. 9 makes as much sense as '3.6 + 1.7' equalling 4. Perhaps even more.


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