Python 生成 1-150 之间不重复的 78 个随机数
使用 Python 生成 1-150 之间不重复的 78 个随机数,可以通过将数字放入列表并随机打乱顺序,然后取出前 78 个数实现。
import random
# 生成 1-150 的数
nums = list(range(1, 151))
# 打乱顺序
random.shuffle(nums)
# 取出前 78 个数
result = nums[:78]
print(result)
原文地址: https://www.cveoy.top/t/topic/lfbC 著作权归作者所有。请勿转载和采集!