random changes

Chris Reedy creedy at mitretek.org
Fri Aug 8 10:26:35 EDT 2003


Tim Peters wrote:
> [dan]
> 
>>I did try random.WichmannHill, which gives completely different data
>>to either the new or the old version.
> 
> 
> I expect you're confused about something, then, but there aren't enough
> details to guess what.
> 
> Here's a run under 2.1.3:
> 
> 
>>>>import random
>>>>random.seed(123456789)
>>>>print repr(random.random())
> 
> 0.095213622685816457
> 
> 
> Here under 2.2.3:
> 
> 
>>>>import random
>>>>random.seed(123456789)
>>>>print repr(random.random())
> 
> 0.095213622685816457
> 
> 
> Here under 2.3:
> 
> 
>>>>import random
>>>>random = random.WichmannHill()
>>>>random.seed(123456789)
>>>>print repr(random.random())
> 
> 0.095213622685816457
> 
> 
> 
> Same thing -- results should be (and are) bit-for-bit identical.  Now show
> us what you do that leads to the "completely different data" conclusion.
> 
> 
Here are some interesting numbers:

 >>> def printstats(rng, N=20000):
         # Cribbed from random._test_generator
	import math
	sum = 0
	sumsq = 0
	for i in range(N):
		x = rng()
		sum += x
		sumsq += x*x
	avg = sum/N
	stddev = math.sqrt(sumsq/N - avg*avg)
	print repr(avg), repr(stddev)

Under 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)]:
 >>> rng = random.Random()
 >>> rng.seed(123456789)
 >>> printstats(rng.random)
0.50177345778280169 0.28856727700571438
 >>> rng.seed(123456789)
 >>> printstats(lambda : rng.normalvariate(0.0, 1.0))
0.0021149783637115457 0.99131361156374964

Under 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)]:
 >>> rng = random.WichmannHill()
 >>> rng.seed(123456789)
 >>> printstats(rng.random)
0.50177345778280169 0.28856727700571438
 >>> rng.seed(123456789)
 >>> printstats(lambda : rng.normalvariate(0.0, 1.0))
0.0064296479176113733 1.0050714625654731

It appears that the numbers for random.random() are identical, however, 
the numbers for normalvariate (and also lognormvariate, betavariate, 
weibullvariate, and paretovariate) are different. I have no explanation 
for why.

   Chris



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----




More information about the Python-list mailing list