python生成随机字符串-python 随机生成字符串数据

不说话字节贴代码:

# -*- coding:UTF-8 -*-

print ("---------------------------game---------------------------")

import re

from random import randint, choice

from string import lowercase

from sys import maxint

from time import ctime

doms = ("com", "edu", "net", "org", "gov")#定义元组

for i in range(randint(10,20)): #循环 10-20次

dtint = randint(0, maxint-1)#获得随机数

dtstr = ctime(dtint) # 格式化时间

shorter = randint(4,7)#获得随机数

em = ""

for j in range(shorter):#循环生成em

em +=choice(lowercase)

longer = randint(shorter,12) #domain

dn = ""

for j in range(longer):#循环生成dn

dn += choice(lowercase)

f=open("email.txt","a+")#打开文件以追加的方式,没有文件则创建文件

x="%s::%s@%s.%s::%d-%d-%d" % (dtstr, em,dn, choice(doms), dtint, shorter, longer)+" "#得到我们想要的字符串一个循环得到一个字符串

f.writelines(x)#写入文件

f.close()#关闭文件

print ("---------------------------game---------------------------")

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26764973/viewspace-1313591/,如需转载,请注明出处,否则将追究法律责任。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值