简单随机验证码生成
random 模块学习
纯数字4位验证码:
1 import random 2 checkcode='' 3 for i in range(4): 4 current=random.randint(1,9) 5 checkcode+=str(currenmt) 6 print (checkcode)
数字+大写字母 4位验证码
1 import random 2 checkcode='' 3 for i in range(4): 4 current=random.randint(1,4) 5 if current=i: 6 tmp=chr(random.randint(65,90)) 7 else: 8 tmp=random.randint(0,9) 9 checkcode+=str(tmp) 10 print (checkcode)
数字+小写字母 4位验证码
1 import random 2 checkcode='' 3 for i in range(4): 4 current=random.randint(0,4) 5 if current=i: 6 tmp=chr(random.randint(97,122)) 7 else: 8 tmp=random.randint(0,9) 9 chechcode+=str(tmp) 10 print (checkcode)
数字+大写+小写 4位验证码:
1 import random 2 checkcode='' 3 for i in range(0,4): 4 current=random.randint(0,4) 5 if current == 1: 6 tmp=chr(random.randint(64,90)) 7 elif current ==2: 8 tmp = chr(random.randint(97.122)) 9 else : 10 tmp=random.randint(0,9) 11 checkcode+=str(tmp) 12 print (checkcode)
用 if进行判断。可以多种验证码。
更多精彩内容:欢迎关注公众号和知识星球
专注实战/Bypass
![](https://files-cdn.cnblogs.com/files/pangya/公众号名片的副本.bmp?t=1653271768)
![](https://files-cdn.cnblogs.com/files/pangya/知识星球二维码.bmp?t=1653273228)