码迷,mamicode.com
首页 > 移动开发 > 详细

python随机产生手机号和邮箱号

时间:2018-11-28 00:25:55      阅读:372      评论:0      收藏:0      [点我收藏+]

标签:perl   pytho   lse   number   lower   its   pen   sci   imp   

1、写个一函数,这个函数的功能是,传入一个数字,产生N条手机号,产生的手机号不能重复。
[150,189,188,170,132,150,186]
def phone(500):
phone.txt
2、写一个函数,这个函数的功能是,传入一个数字,产生N条邮箱,产生的手机号不能重复。
邮箱前面的长度是6-12之间,产生的邮箱必须包含大写字母、小写字母、数字和特殊字符
[163.com,qq.com,sina.com,126.com]

1、

def random_PhoneNumber(N):
import random
l = []
for i in range(N):
s=[150,189,188,170,132,150,186]
h=random.choice(s)
eight=random.randint(10000000,99999999)
p="{}{}".format(h,eight)
if p not in l:
l.append(p)
else:
i -= 1
m=set(l)
phone = ‘\n‘.join(l)
with open(‘phone.txt‘, ‘w+‘) as f:
f.writelines(phone)
return len(m)
print(random_PhoneNumber(500))

2、

def random_email(N):
import string
import random
m = []
l = []
l.append(string.digits)
l.append(string.ascii_letters)
l.append(string.punctuation)
l=‘‘.join(l)
i=0
while i < N:
s = [‘@163.com‘,‘@qq.com‘,‘@sina.com‘,‘@126.com‘]
h = random.choice(s)
rang = random.randint(6,12)
randomNumber = "".join(random.choice(l) for j in range(rang))
email = set(randomNumber)
lowletters = set(string.ascii_lowercase)
upperletters = set(string.ascii_uppercase)
digits = set(string.digits)
punctuation = set(string.punctuation)
if email&lowletters and email&digits and email&punctuation and email&upperletters:
p="{}{}".format(randomNumber,h)
if p not in m:
m.append(p)
i += 1
n=set(m)
phone = ‘\n‘.join(m)
with open(‘email.txt‘, ‘w+‘) as f:
f.writelines(phone)
return len(n)
print(random_email(500))

 

python随机产生手机号和邮箱号

标签:perl   pytho   lse   number   lower   its   pen   sci   imp   

原文地址:https://www.cnblogs.com/arraon/p/10029856.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!