whrandom seed question

Tim Peters tim_one at email.msn.com
Wed Nov 24 01:32:19 EST 1999


[Stelios Kyriacou]
> I tried today the random number generator in python
> and have the following question:

Don't use module whrandom.  Use module random.  The former is an
implementation detail of the latter, and follows the fine scientific
tradition of using incomprehensible calling conventions <0.5 wink>; whrandom
isn't meant to be used directly; random is; someday the docs will catch up
with reality.

> Shouldn't the following 3 lines produce the same number?
>
> >>> whrandom.seed(0,0,0); print whrandom.random()
> 0.39613674715
> >>> whrandom.seed(0,0,0); print whrandom.random()
> 0.170188890936
> >>> whrandom.seed(0,0,0); print whrandom.random()
> 0.831213988577
> >>>
> ...

That's functioning as designed.  You want random.seed and random.random:

>>> import random
>>> random.seed(0); print random.random()
0.0169309061997
>>> random.seed(0); print random.random()
0.0169309061997
>>> random.seed(0); print random.random()
0.0169309061997
>>> print random.seed.__doc__
Seed the default generator from any hashable value.

	None or no argument returns (0, 0, 0) to seed from current time.


>>>

The last sentence there is damaged.  The docstring for random.seed should be

	"""Seed the default generator from any hashable value.

	No argument, or argument None, seeds from current time.
	"""

state-of-sin-indeed-ly y'rs  - tim






More information about the Python-list mailing list