Python生成范围内数字的随机排列

时间:2018-10-01 22:55:04

标签: python random permutation itertools

我正在尝试生成从1到8的4个数字排列的列表。

import random
# initialize a population of permutation
def permutation (pop_size, chrom_length):

    population = []

    #code begin



    #code end
    return population 

pop_size变量是列表的长度,chrom_length是每个排列的长度

1 个答案:

答案 0 :(得分:1)

看看python的itertools模块:)。

您可以尝试以下操作:

import itertools

def permutation(pop_size, chrom_length):
    return itertools.permutation(pop_size, chrom_length)
相关问题