1.使用random和string模块
from __future__ import print_function import random import string ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 16)) print(ran_str)
2.使用uuid和time模块
from __future__ import print_function import uuid import hashlib import time def create_md5(): #通过MD5的方式创建 m=hashlib.md5() m.update(bytes(str(time.time()),encoding='utf-8')) return m.hexdigest() if __name__ == '__main__': print(create_uuid()) print(create_md5())
参考资料
https://www.cnblogs.com/nulige/p/6216659.html