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模块全部内容,希望文章能够帮你解决python自动化2021/04/14 radom模块所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)