随机生成6位数验证码

方法一:

 1 import random
 2 def generate_code():
 3     code_list=[]
 4     for i in range(10):
 5         code_list.append(str(i))
 6     for i in range(65,91):
 7         code_list.append(chr(i))
 8     for i in range(97,123):
 9         code_list.append(chr(i))
10     mystlic=random.sample(code_list,6)
11     ver_code=‘‘.join(mystlic)
12     return ver_code

方法二:

def generate_verification_code2():
    ‘‘‘ 随机生成6位的验证码 ‘‘‘
    code_list = []
    for i in range(2):
        random_num = random.randint(0, 9) # 随机生成0-9的数字
        # 利用random.randint()函数生成一个随机整数a,使得65<=a<=90
        # 对应从“A”到“Z”的ASCII码
        a = random.randint(65, 90)
        b = random.randint(97, 122)
        random_uppercase_letter = chr(a)
        random_lowercase_letter = chr(b)

        code_list.append(str(random_num))
        code_list.append(random_uppercase_letter)
        code_list.append(random_lowercase_letter)
    verification_code = ‘‘.join(code_list)
    return verification_code


原文地址:https://www.cnblogs.com/lishun412/p/9231338.html

时间: 2024-08-13 06:54:52

随机生成6位数验证码的相关文章

python随机生成6位数验证码

#随机生成6位数验证码 import randomcode = []for i in range(6):    if i == str(random.randint(1,5)):        code.append(i)    else:       temp =  random.randint(65,90)       code.append(chr(temp)) print ''.join(code) ###扩充random用法,随机生成树,和程序无关 print random.rando

python 之随机生成6位数验证码

#!/usr/bin/env python # -*- coding: utf-8 -*- #用于生成随机数的模块:random #函数chr()返回对应的ASCII字符,与ord()作用相反. import random #在1-100之间生成随机数 num = random.randint(1,100) #随机生成一个大写字母,ASCII码值65-90对应的是A-Z cap = chr(random.randint(65,90)) #随机生成一个小写字母,ASCII码值97-122对应的是a

java 随机生成四位数验证码

public static void main(String[] args) { // TODO 自动生成的方法存根 Random r=new Random(); String str="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//列出所有的字母数字 for(int i=0;i<4;i++)//循环4次,输出四个数 { int a=r.nextInt(62);//从0-61中随机一个数,作为字

js随机生成4位验证码

方法一: /*随机生成4位验证码*/ /*step1:将所有字母,数字装入一个数组备用*/ var codes=[]; //数字:48-57;unicode编码 for(var i=48;i<57;codes.push(i),i++); /*console.log(codes);*/ //大写字母:65-90;unicode编码 for(var i=60;i<90;codes.push(i),i++); //小写字母:97-122;unicode编码 for(var i=97;i<122

为产品或者商品随机生成6位数的数字编码方案

--为产品或者商品随机生成6位数的数字编码方案 --准备阶段 --建立一个表,生成100000到999999顺序编码 create table #no (  id int ) declare @id int  set @id=1 while(@id<=999999) begin  insert into #no values(@id)  set @[email protected]+1 end --建立随机编码表 create table RNo (  id int identity(1,1),

随机生成指定位数的验证码

import randomimport 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_

js随机生成N位数

function RondomPass(number){ var arr = new Array; var arr1 = new Array("0","1","2","3","4","5","6","7","8","9"); for(var i=0;i<number;i++){ var n = Math

随机生成文字图片验证码

1.随机生成汉字 //传入你要生成汉字的个数 public string GetGB2312String(int count) { var random = new Random(); var bs = new byte[count * 2]; for (var i = 0; i < count; i++) { var c = GetGB2312Char(random); bs[i * 2] = (byte)(c.X + 0xa0); bs[i * 2 + 1] = (byte)(c.Y + 0

python3 随机生成6位数的验证码

要求是数字:0~9 及大小写字母. #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import random # 48--57 : 0-9 # 65--90 : A-Z # 97--122: a-z index = 6 count = 0 str1 = '' #存放验证码 while index > count: num = random.randrange(48,122) if (num <= 57) or