# random ###### tags: `python package` `NLP` `繁體中文斷詞` 參考: http://www.runoob.com/python/func-number-random.html [Toc] {%hackmd @rpyapp/theme %} # 常用的隨機抽取方法 ## 整數 ```python= random.randint(1,10) # 隨機產生 1~10 之間的整數 random.randrange(0,100,2) # 0~100 之間的偶數(間格=2) ``` ## 浮點數 ```python= random.random() # 隨機產生 0~1 之間的 float random.uniform(1.1,5.4) # 隨機產生 1.1 ~ 5.4 之間的 float ``` ## 序列裡的 elelment ```python= text = 'tomorrow' random.choice(text) # 從序列中隨機選取一個 element random.sample(text,2) # 從序列中隨機抽取兩個(多個) element ``` ## 打亂順序 ```python= a=[1,3,5,6,7] random.shuffle(a) print(a) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up