小编kra*_*ase的帖子

列表中的python随机序列

如果我的列表范围从0到9,例如.我如何使用random.seed函数从该范围的数字中随机选择?另外我如何定义结果的长度.

import random

l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a = 10
random.seed(a)
length = 4

# somehow generate random l using the random.seed() and the length.
random_l = [2, 6, 1, 8]
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
8676
查看次数

标签 统计

python ×1