Numeric RandomArray seed problem
Robert Kern
robert.kern at gmail.com
Mon Jan 2 20:52:06 EST 2006
ajikoe at gmail.com wrote:
> Hello,
>
> I tried calling RandomArray.seed()
> by calling RandomArray.get_seed() I get the seed number (x,y).
> My problem is that x is always 113611 any advice?
Well, RandomArray.seed() gets its seed from the computer's time.
def seed(x=0,y=0):
"""seed(x, y), set the seed using the integers x, y;
Set a random one from clock if y == 0
"""
if type (x) != IntType or type (y) != IntType :
raise ArgumentError, "seed requires integer arguments."
if y == 0:
import time
t = time.time()
ndigits = int(math.log10(t))
base = 10**(ndigits/2)
x = int(t/base)
y = 1 + int(t%base)
ranlib.set_seeds(x,y)
As you can see, x won't change much if the difference in t is small.
Note, that in scipy_core, the random number facilities have been
completely rewritten. We now use the Mersenne Twister algorithm, which
uses 2496 bytes of state instead of 8 like RandomArray. On UNIX-type
systems with a /dev/urandom and also Windows, the default seed (all
2496 bytes of state) is drawn from the OS's "cryptographic PRNG" where
available.
More information about the Python-list
mailing list