灵虚御风
醉饮千觞不知愁,忘川来生空余恨!

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 
# 随机模块
import random

# print(random.randint(1,6)) # 1 # 随机取一个你提供的整数范围内的数字 包含首尾

# print(random.random()) # 0.2636316825914742 # # 随机取0-1之间小数

# print(random.choice([1,2,3,4,5,6])) # 摇号 随机从列表中取一个元素

# res = [1,2,3,4,5,6]
# random.shuffle(res) # 洗牌
# print(random.choice([1,2,3,4,5,6]))# 摇号 随机从列表中取一个元素

# res = [1,2,3,4,5,6]
# random.shuffle(res) # 洗牌
# print(res)

# 生成随机验证码
"""
大写字母 小写字母 数字

5位数的随机验证码
chr
random.choice
封装成一个函数,用户想生成几位就生成几位
"""

def get_code(n):
code = ''
for i in range(n):
# # 先生成随机的大写字母 小写字母 数字
upper_str = chr(random.randint(65,90))
lower_str = chr(random.randint(97,122))
random_int = str(random.randint(0,9))
# 从上面三个钟随机选择一个作为随机验证码的某一位
code += random.choice([upper_str,lower_str,random_int])
return code
res = get_code(4) # OYwJ
print(res)



posted on   没有如果,只看将来  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
 
点击右上角即可分享
微信分享提示