I notice that if I seed Python's PRNG with a tuple, I get different results each time I do it. That is, the Python 3.4 program:
import random
seed1 = ('Foo', 'Bar')
random.seed(seed1)
print(random.random())
prints a different number each time it is run. Is this because the seed taken is the id of the tuple seed1 which is different each time?
What is the best way to use a tuple as a seed to the PRNG so that I get repeatable results? Is it simply random.seed(str(seed1))?
From a previous question:
So using python 2.x, running
hash('Foo', 'Bar')will generally return the same result on the same computer each time which gives you the same initial seed. On python 3.3+ runninghashagainst your tuple gives you a unique value each time.If you want to have a consistent result with python 3.3+ look into
hashlib. For example:i.e. you'll have a consistent seed, but since the random modules differ in their implementation you still get a different random number.