Re: Shock: rand function is not uniform!

[email protected] (Roger Horne) Tue, 19 Feb 2002 22:38:50 +0000 (GMT)
Newsgroups perl.riscos
Message-ID <Marcel-1.53-0219223850-313Wr#[email protected]>
On Tue 19 Feb, Justin Fletcher wrote:

> > I think your condescension is rather unnecessary.
> 
> I think your belief that empirical evidence is proof is wrong; which
> is what I'm stating.

Um .... 

The question of the randomness of numbers is dealt with in the Perl Cookbook
as:

##
Problem

You want to generate numbers that are more random than Perl's random
numbers. Limitations of  your C library's random number generator seeds will
sometimes cause problems. The sequence of pseudo-random numbers may repeat
too soon for some applications.

Solution

Use a different random number generator, such as those provided by the
Math::Random and  Math::TrulyRandom modules from CPAN:

use Math::TrulyRandom; $random = truly_random_value();

use Math::Random; $random = random_uniform();

Discussion

Perl uses the standard C library routine rand (3) to generate pseudo-random
numbers. (This can  be changed at build time, however.) Some implementations
of the rand function return only 16-bit random numbers or have algorithmic
weaknesses and may not be sufficiently random.

The Math::TrulyRandom module uses the inadequacies of your system's timers
to generate the  random numbers. This takes a while, so it isn't useful for
generating a lot of random numbers.

The Math::Random module uses the randlib library to generate random numbers.
It also  includes a wide range of related functions.
##

(Not that I understand any of it. Random numbers to me are things that my
fingers type in unintentionally when I try to enter a PIN.)


Roger
-- 
Roger Horne
11 New Square, Lincoln's Inn, London WC2A 3QB
mailto:[email protected]
http://www.hrothgar.co.uk/