摘录自RONOOB.com | Python 生成随机数、随机字符串
import random
import string
print random.randint(1,50)
print random.randrange(0, 101, 2)
print random.random()
print random.uniform(1, 10)
print random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
print random.sample('zyxwvutsrqponmlkjihgfedcba',5)
ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 8))
print ran_str
print ''.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)
|