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
John Peacock
March 6, 2001 06:45
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID: wrote:
> Well, if it doesn't than rand() is having a problem; and that doesn't
> have anything to do with 'use integer' or not. After all, if you cannot
> expect int(rand(10)) not to give 10% 0s, 10% 1s, .. 10% 9s, the values
> it returns are not uniformely distributed.

Since none of the math experts on the list have objected, I guess we
are OK with the assumption that int(rand(10)) will be fine.

> Having said that, having 'rand' returning integers when 'use integer'
> is in effect fits exactly in Perls DWIM nature.

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.

> Abigail

John Peacock

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