[IPython-dev] random.seed() Was: [FWD] An interesting take on the Notebook Problem

Hans Meine hans_meine at gmx.net
Thu Sep 29 09:57:20 CDT 2005

On Monday 01 August 2005 18:21, Hans Meine wrote:
> > random.seed() deterministically sets the whole state from an
> > integer/long. Calling random.seed() should be enough.
> That's what I thought, too.  However, I tried that with a unit-testing
> program which draws a lot more than 20 numbers, and there was a difference
> (fatal for me).  That is the whole reason for my posting, because what you
> wrote was exactly my understanding of a "seed".

I finally found out what caused my problems.  This is how my program started:

import random, time
if len(sys.argv) > 1:
    seed = long(sys.argv[1])
    seed = time.time()

print "using %d as seed." % (seed, )

This is for stochastic unit-testing, but when it fails, I wanted to be able to 
reproduce that, see the cmdline parameter.  Now please tell me if you see the 

*** solution follows ***

I found it: time.time() gives a float, but the %d output silently truncates 
it.  Seeding with the float does something different (IIRC, the docs say that 
any hashable object can be used for seed()ing, but seed(hash(seed)) is *not* 
what happens).

Sorry for the noise, but you know this satisfied feeling when you finally 
found an explanation.. ;-)

Have a nice day,

PS: My next posting will be on-topic again, promised! :-)

More information about the IPython-dev mailing list