jeudi 14 juillet 2016

How can I get same result with same seed set at random.shuffle()

I have the following code:

import random
SEED = 448

myList = [ 'list', 'elements', 'go', 'here' ]
random.seed(SEED)
random.shuffle(myList)  
print "RUN1: ", myList

random.seed(SEED)
random.shuffle(myList)  
print "RUN2: ", myList

Now I expect RUN1 and RUN2, produces the same result:

RUN1:  ['here', 'go', 'list', 'elements']
RUN2:  ['here', 'go', 'list', 'elements']

But it gives this instead.

RUN1:  ['here', 'go', 'list', 'elements']
RUN2:  ['elements', 'list', 'here', 'go']

How can I modify my code to get the result behavior as I expected?




Aucun commentaire:

Enregistrer un commentaire