两个解决方案:
方案一:
import uuid
class Generation:
def __init__(self):
self.num = 0
self.listid = []
def generate_uuid(self, num):
for i in range(int(num)):
self.listid.append(uuid.uuid1())
def get__uuid(self):
return self.listid
if __name__ == '__main__':
gencode = Generation()
gencode.generate_uuid(200)
keys = gencode.get_uuid()
filekeys = file('gencodes.txt', 'w')
for k in keys:
filekeys.write(str(k)+'\n')
filekeys.close()
方案二:
import string, random
#激活码中的字符和数字
field = string.letters + string.digits
#获得四个字母和数字的随机组合
def getRandom():
return "".join(random.sample(field,4))
#生成的每个激活码中有几组
def concatenate(group):
return "-".join([getRandom() for i in range(group)])
#生成n组激活码
def generate(n):
return [concatenate(4) for i in range(n)]
if __name__ == '__main__':
print(generate(200))
或多或少在我的电脑上都有问题
所以我自己的方案是:
import random
def __init__(self):
pass
def ch():
git=[chr(i) for i in range(97,123)]
dit=[int(i) for i in range(0,10)]
field=git+dit
return field
def ver(field,num):
for j in range(20):
r=[]
for i in range(5):
x=random.sample(field,4)
r=r+x
r1=[str(i) for i in r]
print(''.join(r1))
if __name__=="__main__":
ver(ch(),20)
网友评论