代码:
'''
import random def phone(): #创建手机号第二位 second=random.choice([3,4,5,7,8,9]) #从这个list里面随机选择一个数字 #创建手机号第三位 third={ 3:random.randint(0,9), #从0-9之间随机生成一个整数int类型 4:random.choice([5,7,9]), #4:[5,7,9][random.randint(0,2)], 5:random.choice([0,1,2,3,4,5,7,8]), #5:[i for i in range(10) if i !=4][random.randint(0,8)], 7:random.choice([2,3,5,6,7,8]), #7:[i for i in range(10) if i not in [4,9]][random.randint(0,7)], 8:random.randint(0,9), 9:random.choice([1,3,8,9]), #9:[1,3,8,9][random.randint(0,2)], }[second] #third后面加上second是由于third的生成要依赖second的随机选择结果 #创建手机号最后八位 suffix=random.randint(9999999,100000000) #拼接手机号 return "1{}{}{}".format(second,third,suffix) #创建批量生成手机号的循环 for i in range(100): randomphone=phone() f = open('token.txt', 'a') f.write(randomphone) f.write('\r') print(randomphone)