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
Philip Newton
March 7, 2001 01:56
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID:
On 6 Mar 2001, at 14:08, John Peacock wrote:

> The problem comes when someone codes this:
> use integer;
> for(;;) {
>         print rand;
> }
> because this has no meaning.

I'd say it has the meaning: print(int(rand()) -- that is, using rand's 
default argument of 1. Of course, a function that always returns 0 is 
not very useful, but that's another thing.

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

The set (0, 1) would be wrong as the output for int(rand()) or 
int(rand(1)) IMO -- rand() is defined to be rand(1) which is defined to 
give a value x with 0 <= x < 1. Hence, truncating that should always 
give 0.

Philip Newton <>
I appreciate copies of replies to my messages to Perl5 lists.

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