random.seed()以及random.shuffle()

结论:当random.seed()设定一个初始值时,random.shuffle()的顺序保持不变

 

>>> import random
>>> SEED = 1
>>> random.seed(SEED)
>>> a=[i for i in range(10)]
>>> random.shuffle(a)
>>> print(a)
[6, 8, 9, 7, 5, 3, 0, 4, 1, 2]
>>> random.shuffle(a)
>>> print(a)
[5, 1, 9, 0, 3, 2, 6, 4, 8, 7]



>>> random.seed(SEED)
>>> b=[i for i in range(10)]
>>> random.shuffle(b)
>>> print(b)
[6, 8, 9, 7, 5, 3, 0, 4, 1, 2]
>>> random.shuffle(b)
>>> print(b)
[5, 1, 9, 0, 3, 2, 6, 4, 8, 7]

 

你可能感兴趣的:(random.seed()以及random.shuffle())