number generator

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Mar 10 18:53:03 EST 2007


On Sat, 10 Mar 2007 08:29:09 -0800, Paul Rubin wrote:

> Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> writes:
>> Doesn't mean that it isn't random. After all, the first four numbers are
>> random, therefore their sum is random. 50 - (something random) is also
>> random.
> 
> What does it mean for the first 4 numbers to be random?  For example,
> is 27 random?

In isolation, no, but 27 could have been chosen at random and hence would
have been unpredictable. That was my point: if we generate four
unpredictable numbers (using random.randint or similar) and sum them, the
sum is also unpredictable, and hence the difference between 50 and that
sum is unpredictable.


> By your method, what is the probability of the first number being
> higher than 30?  What is the probability of the fifth number being
> higher than 30?  If these probabilities are unequal, can we really say
> the sequences are random?

Of course we can! "Uniform probability distribution" is a special case of
random. Most random quantities are far from uniform. The Python random
module includes a couple of non-uniform distributions, including
exponential distribution (random.expovariate) and the famous bell curve
distribution (random.normalvariate).

One common distribution which seems to have been missed is the Poisson
distribution, which applies to (among many, many others) the number of
18th Century Prussian cavalry officers who fell off their horse and broke
a limb, and the number of cars arriving at a petrol station in any hour.



-- 
Steven.




More information about the Python-list mailing list