[Python-checkins] python/dist/src/Lib/test test_random.py,NONE,1.1

tim_one@sourceforge.net tim_one@sourceforge.net
Sun, 05 May 2002 13:40:02 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv14885/python/Lib/test

Added Files:
	test_random.py 
Log Message:
random.gauss() uses a piece of hidden state used by nothing else,
and the .seed() and .whseed() methods failed to reset it.  In other
words, setting the seed didn't completely determine the sequence of
results produced by random.gauss().  It does now.  Programs repeatedly
mixing calls to a seed method with calls to gauss() may see different
results now.

Bugfix candidate (random.gauss() has always been broken in this way),
despite that it may change results.


--- NEW FILE: test_random.py ---
import test_support
import random

# Ensure that the seed() method initializes all the hidden state.  In
# particular, through 2.2.1 it failed to reset a piece of state used by
# (and only by) the .gauss() method.

for seed in 1, 12, 123, 1234, 12345, 123456, 654321:
    for seeder in random.seed, random.whseed:
        seeder(seed)
        x1 = random.random()
        y1 = random.gauss(0, 1)

        seeder(seed)
        x2 = random.random()
        y2 = random.gauss(0, 1)

        test_support.vereq(x1, x2)
        test_support.vereq(y1, y2)