#1.使用python random模塊的choice方法隨機選擇某個元素
import random
foo = ['a', 'b', 'c', 'd', 'e']
from random import choice
print choice(foo)
#2.使用python random模塊的sample函數從列表中隨機選擇一組元素
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#設置種子使得每次抽樣結果相同
random.seed(10)
slice = random.sample(list, 5) #從list中隨機獲取5個元素,作爲一個片斷返回
print slice
print list #原有序列並沒有改變。