develooper Front page | perl.perl5.porters | Postings from April 2001

Re: [ID 20010305.005] "use integer" doesn't make rand() return integers

Thread Previous | Thread Next
From:
Walt Mankowski
Date:
April 28, 2001 22:07
Subject:
Re: [ID 20010305.005] "use integer" doesn't make rand() return integers
Message ID:
20010429010727.A28087@netaxs.com
On Mon, Mar 05, 2001 at 04:15:26PM -0500, Robert Spier wrote:
> JP> I agree that the patch should not go in; my point was I'm not even
> JP> sure that int(rand(10)) will not bias the random sequence returned
> JP> by rand().  When dealing with random numbers, I know enough to
> JP> know only that I don't know enough!  ;~)
> 
> I don't know enough either, but I'm pretty sure that "bias" is the
> wrong word.  It will "quantize" the results.  But they should still be 
> evenly[1] distributed between 0 and 9.  All that int (or floor) does is
> chop off the non integer parts... It's not going to shift the nubers
> up or down.  They will still be between 0 and 9.99999999999...
> 
> -R
> 
> [1] or as random as they were before we started mucking, however
> random or un-random that might be.

And all rand(10) does is multiply the value returned by Perl's
internal rand() function by 10.  It will affect the precision of the
results returned, but not how evenly they're distributed.

Walt

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