Checkthis's Notes
2017年9月30日 星期六
Python - Random筆記
import random
幫串列洗牌
a = list(range(1,11))
random.shuffle(a)
隨機產生一個範圍的整數
random.randint(0,10) # 0..9
隨機產生浮點數
random.random()
random.uniform(1, 10) # 1..9
隨機產生字元
random.choice('abcdefg') # b
選取多個字元轉換串列
random.sample('abcdefghij',3) # ['c', 'f', 'a']
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言