生成的都是字母
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import random
def sele_num():
temp = ''
for i in range(6):
random
rad = random.randrange(65,91)
c = chr(rad)
temp = temp + c
return temp
a = sele_num()
print(a)
升级版,包括字母和数字的验证码
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import random
def sele_num2():
temp = ''
for i in range(6):
ii = random.randrange(0,4)
if ii == 2 or ii ==4:
rad2 = random.randrange(0,10)
temp = temp + str(rad2)
else:
rad1 = random.randrange(65,91)
c1 = chr(rad1)
temp = temp + c1
return temp
b = sele_num2()
print(b)