即使在调用random.seed()之后,Python random.shuffle()产生相同的结果?

时间:2016-09-18 13:55:48

标签: python python-3.x

# N-Queens Problem
import random

# Define size of board
SIZE_OF_BOARD = 8
POPULATION_SIZE = 50

population = []

startingIndividual = []
# Populate starting individual
for x in range(0, SIZE_OF_BOARD):
    startingIndividual.append(x)

for x in range(0, POPULATION_SIZE - 1):
    population.append(startingIndividual)

for x in population:
    random.seed()
    random.shuffle(x)

print(population)

所以,当我运行这个程序时,我得到相同的排列50次。即使我为每个列表重新调整了shuffle,我也在洗牌,结果仍然是一样的。我到底哪里错了?

0 个答案:

没有答案