如何生成50个随机数,使得第一个数字介于1和2之间,第二个介于1和3之间,第三个介于1和4之间,...,最后一个介于1和5之间python 3。
答案 0 :(得分:1)
您可以尝试:
>>> from random import randint
>>> l = []
>>> for i in range(2,51):
l.append(randint(1,i))
>>> l
[1, 2, 4, 2, 6, 6, 3, 4, 5, 7, 6, 12, 8, 3, 10, 13, 8, 8, 7, 12, 22, 6, 9, 7, 20, 6, 14, 24, 17, 14, 10, 15, 28, 7, 3, 15, 3, 16, 40, 3, 42, 15, 42, 16, 43, 20, 7, 37, 7]