Python模块random

来源:互联网 发布:淘宝潮流女装店铺 编辑:程序博客网 时间:2024/06/15 18:09

1、参考链接

https://docs.python.org/3/library/random.html

Python版本:3.5.3

2.常用函数

(1).随机整数

print random.randint(5, 30)

(2).随机浮点数

0到1的随机浮点数
print (random.random())
10到20的随机浮点数
print (random.uniform(10, 20))

(3).随机选取0到200间的偶数

print(random.randrange(0, 201, 2))

(4).随机字符

print(random.choice('ASDFGHJKL;'!@#$%^'))
print(random.choice ( ['运维架构师', '程序猿', '程序媛', 'DBA', 'DEVOPS'] ))
1 0