首页 > 编程语言 > 详细

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

时间:2021-04-15 15:24:45      阅读:31      评论:0      收藏:0      [点我收藏+]
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())

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

原文:https://www.cnblogs.com/lp19910807/p/14661401.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!