35、python模块学习-radom随机生成数
#!/usr/bin/env python
#__author: hlc
#date: 2019/6/7
# 随机数模块
# import random
# print(random.random()) # 随机生成0-1的数
# print(random.randint(1,8)) # 随机生成1-8的整数(包括1和8)
# print(random.choice(["123","asdf","gfhdf"])) # 随机取值
# print(random.sample(["123","asdf","gfhdf"],2)) # 随机取2个值
# print(random.randrange(1,5)) # 随机取值;不包含5
# 生成一个5位随机验证码
# def v_code() :
# code = ""
# for i in range(5) :
# add_num = random.randrange(10)
# code += str(add_num)
# print(code)
# v_code() # 04799
# 生成阿斯克码方法
# print(chr(36)) # $
# 生成5位数字加字母
# def v_code() :
# code = ""
# for i in range(5) :
# add = random.choice([random.randrange(10),chr(random.randrange(65,91))])
# code += str(add)
# print(code)
# v_code() # Q5QD8