标签:图片 weight src ima pre char png imp alt
import random
import string
# 方法一:
def code_1(m, choice):
code=‘‘.join(random.sample(choice, m))
return code
print(code_1(4, string.ascii_letters + string.digits))
# 方法二:
def code_2(n):
code=‘‘
for i in range(n):
number=random.randint(0, 9) # 0-9
lower_char=chr(random.randint(97, 122)) # a-z
upper_char=chr(random.randint(65, 90)) # A-Z
char_1=random.choice([number, lower_char, upper_char])
code+=str(char_1)
return code
print(code_2(4)
先上代码。。。高效如我 ^ ^..。颜色怪怪的、不要介意哈~
print(random.randint(1,100))
print(random.randrange (0,100,2))
print(random.randrange ( 1 , 100 , 2))
print(random.random())
print(random.uniform(1,10))
print(random.choice(r‘qwertyuiop[]\asdfghjkl;zxcvbnm,./‘))
print(code=‘‘.join(random.sample(choice, m)))
其中choice为备选字符串,m为生成的验证码个数
标签:图片 weight src ima pre char png imp alt
原文地址:https://www.cnblogs.com/aqin1012/p/11615371.html