python自动化2021/04/14 radom模块

import random

# #0-1的随机浮点数
# print(random.random())
#
# #1-3之间的浮点数
# print(random.uniform(1,3))
#
# #随机整数
# print(random.randint(1,5))
#
# #顾头不顾尾
# print(random.randrange(1,5))
#
# #从序列元素中随机选取一个
# print(random.choice(["张三","李四","王五"]))
#
# #列表元素任意n个组合
# print(random.sample([1,2,3,4,5,6,7,8],2))
#
# #打乱次序
# l = [1,234,54,5]
# # l.sort()
# # l.reverse()
# # print(l)
# random.shuffle(l)
# print(l)


#案例: 生成随机验证码
# for i in range(65,91 ): #A-Z
# print(chr(i))
# for i in range(97,123): #a-z
# print(chr(i))
# def v_code():
# code = ''
# for i in range(2):
# num = random.randint(0,10)
# code += str(num)
# alf_upper = chr(random.randint(65,91))
# alf_lower = chr(random.randint(97,123))
# code = "".join([code,str(alf_upper),str(alf_lower)])
# return code
# print(v_code())


def v_code():
code = ''
for i in range(1):
num = random.randint(0,10)
alf_upper = chr(random.randint(65,91))
alf_lower = chr(random.randint(97,123))
code += random.choice([str(num),alf_upper,alf_lower])
print(code)
code = "".join([code,str(alf_upper),str(alf_lower)])
return code
print(v_code())

posted @ 2021-04-15 10:42  lpaxq  阅读(65)  评论(0编辑  收藏  举报