#coding=utf-8 import random, time #随机生成中文 def user_name(length=3): str = u'' for i in range(length): val = random.randint(0x4E00, 0x9FBF) str += unichr(val) return str #随机生成字符串 def password(length=8): str = '' chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' chars_lenght = len(chars) - 1 for i in range(length): str += chars[random.randint(0, chars_lenght)] return str def date(): t = int(random.random() * 10000000000) return time.strftime("%Y-%m-%d", time.localtime(t)) # 随机生成手机号码 def phone(): prelist = ["130","131","132","133","134","135","136","137","138","139","147","150","151","152","153","155","156","157","158","159","186","187","188"] return random.choice(prelist) + "".join(random.choice("0123456789") for i in range(8)) # 随机生成18位身份证号 def card(): ARR = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2) LAST = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2') t = time.localtime()[0] x = '%02d%02d%02d%04d%02d%02d%03d' %(random.randint(10,99), random.randint(01,99), random.randint(01,99), random.randint(t - 80, t - 18), random.randint(1,12), random.randint(1,28), random.randint(1,999)) y = 0 for i in range(17): y += int(x[i]) * ARR[i] return '%s%s' %(x, LAST[y % 11])