参考网上的文章来学习,感谢原作者!(不好意思,忘了在哪看的了)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2016/12/12 下午1:10
# @Author : hukezhu
# @Site :
# @File : 0001:生成200个激活码.py
# @Software: PyCharm
#这是使用随机数的方法
# import string as s
# import random as r
#
#
# def randomNum():
# f = open('/Users/hukezhu/Desktop/随机数激活码.txt','w+')
# for i in range(200):
# randomStr = ''.join(r.choice(s.ascii_uppercase + s.digits) for x in range(10)) + '\n'
# f.write(randomStr)
# f.close()
#
#
# if __name__ == '__main__':
# randomNum()
#直接使用UUID模块
# import uuid as u
#
# def rand_uuid():
# f = open('/Users/hukezhu/Desktop/UUID随机激活码.txt','w+')
# for i in range(200):
# ID = str(u.uuid1()) + '\n'
# f.write(ID)
#
# f.close()
#
#
#
# if __name__ == '__main__':
# rand_uuid()
#使用主键和随机码
import string as s
import random as r
def rand_ID():
f = open('/Users/hukezhu/Desktop/主键和随机码随机码.txt','w+')
for i in range(200):
ID = id(i)
rand_id = str(ID)[5:]
null = ''
for j in rand_id:
null += j + r.choice(s.ascii_uppercase)
f.write(null + '\n')
f.close()
if __name__ == '__main__':
rand_ID()