mardi 9 juin 2015

Python random use both state and seed?

Seeding Python's built-in (pseudo) random number generator will allows us to get the same response each time we use that seed -- documentation here. And I've heard saving the internal state of the generator reduces the likelihood of repeating values from previous inputs. Is this necessary? That is, is getState() and setState() in the below code unnecessary in order to get the same results every time I seed with "foo"?

import random
...
state = random.getstate()
random.seed("foo")
bitmap = random.sample(xrange(100), 10)
random.setstate(state)
return bitmap




Aucun commentaire:

Enregistrer un commentaire