Creating a more random int?

Tim Chase python.list at tim.thechases.com
Tue Jan 24 12:53:23 EST 2006


> I need to retrieve an integer from within a range ... this
> works ... below is my out puts ... it just does not seem so
> random ...
> 
> Is there perhaps a suggestion out there to create a more
> random int ...?

I'm not sure how you determine that "it just does not seem so
random"...I tried the following:

	>>> import random
	>>> samples = 10000
	>>> x = [random.randint(3,8) for i in range(1,samples+1)]
	>>> s = 0
	>>> for i,j,k in [(i,x.count(i), (samples/6.0)-x.count(i)) for i
in range(3,9)]:
	...     print i,j,k
	...	s = s + k
	...
	3 1735 -68.3333333333
	4 1634 32.6666666667
	5 1608 58.6666666667
	6 1688 -21.3333333333
	7 1670 -3.33333333333
	8 1665 1.66666666667
	>>> s
	-5.6843418860808015e-14

It also seems to hover fairly closely about the mid-point in 
terms of distribution.  Looks like a fairly decent sampling to 
me.  Is there some statistical test it's failing for you?

-tim









More information about the Python-list mailing list