samedi 21 septembre 2019

Python "set" producing inconsistently random sets

I have the following code:

from random import seed
seed(5)
s = 'the quick brown fox jumps over the lazy dog'
s = list(set(s))
print(s)

When running this multiple times, the list always turns out differently:

>>>['b', 'y', 'i', 'g', 'j', 'o', 'x', 'u', 'l', 'c', 't', 'a', ' ', 's', 'z', 'h', 'n', 'd', 'k', 'v', 'r', 'w', 'p', 'f', 'm', 'q', 'e']
>>>['k', 'o', 'q', 'g', 'a', 'y', 'b', 'z', 'e', 'l', 's', 'm', 't', 'x', ' ', 'r', 'j', 'w', 'n', 'h', 'u', 'f', 'i', 'c', 'd', 'p', 'v']
>>>['l', 'y', 'h', 'o', 'q', 'f', 'm', 'e', 'v', 'r', 'k', 'w', 't', 's', 'd', 'u', 'b', 'i', 'a', 'z', 'g', 'p', 'c', 'n', ' ', 'x', 'j']

How do I seed this so it is consistent?




Aucun commentaire:

Enregistrer un commentaire