python生成隨機數、隨機字串
import random
import string
# 隨機整數:
print random.randint(1,50)
# 隨機選取0到100間的偶數:
print random.randrange(0, 101, 2)
# 隨機浮點數:
print random.random()
print random.uniform(1, 10)
# 隨機字元:
print random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
# 多個字元中生成指定數量的隨機字元:
print random.sample('zyxwvutsrqponmlkjihgfedcba',5)
# 從a-za-z0-9生成指定數量的隨機字元:
ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 8))
print ran_str
# 多個字元中選取指定數量的字元組成新字串:
prin ''.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'], 5))
# 隨機選取字串:
print random.choice(['剪刀', '石頭', '布'])
# 打亂排序
items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
print random.shuffle(items)
python生成隨機數、隨機字串
import random
import string
# 隨機整數:
print random.randint(1,50)
# 隨機選取0到100間的偶數:
print random.randrange(0, 101, 2)
# 隨機浮點數:
print random.random()
print random.uniform(1, 10)
# 隨機字元:
print random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
# 多個字元中生成指定數量的隨機字元:
print random.sample('zyxwvutsrqponmlkjihgfedcba',5)
# 從a-za-z0-9生成指定數量的隨機字元:
ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 8))
print ran_str
# 多個字元中選取指定數量的字元組成新字串:
prin ''.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'], 5))
# 隨機選取字串:
print random.choice(['剪刀', '石頭', '布'])
# 打亂排序
items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
print random.shuffle(items)
隨機生成隨機數
現畫乙個command命令按鈕,進行貼上。private sub command1 click show me scale 0,0 18,8 me.auto redraw true me.draw mode 2 circle 3,4 3,vb red me.auto redraw false lin...
python隨機數生成
python中的random模組用於生成隨機數。下面介紹一下random模組中最常用的幾個函式。random.random random.random 用於生成乙個0到1的隨機符點數 0 n 1.0 random.uniform random.uniform的函式原型為 random.uniform...
Python生成隨機數
import random import string 隨機整數 print random.randint 1,50 隨機選取0到100間的偶數 print random.randrange 0,101,2 隨機浮點數 print random.random print random.uniform...