当前位置: 编程技术>python
python生成随机验证码(中文验证码)示例
来源: 互联网 发布时间:2014-10-04
本文导语: 代码如下:# -*- coding: utf-8 -*-import Image,ImageDraw,ImageFontimport randomimport math, string class RandomChar(): """用于随机生成汉字""" @staticmethod def Unicode(): val = random.randint(0x4E00, 0x9FBF) return unichr(val) @staticmethod def GB2312(): ...
代码如下:
# -*- coding: utf-8 -*-
import Image,ImageDraw,ImageFont
import random
import math, string
class RandomChar():
"""用于随机生成汉字"""
@staticmethod
def Unicode():
val = random.randint(0x4E00, 0x9FBF)
return unichr(val)
@staticmethod
def GB2312():
head = random.randint(0xB0, 0xCF)
body = random.randint(0xA, 0xF)
tail = random.randint(0, 0xF)
val = ( head