1. 程式人生 > >python生成一個不重複的隨機數

python生成一個不重複的隨機數

import random

list1 = [0,1,2,3,4,5,6,7,8,9]
list2 = ['a','b','c','d','e','f','g','h','i','j','k']
num1 = random.sample(list1,4)
num2 = random.sample(list2,5)
print(num1)
print(num2)

執行結果