生成一个随机唯一的字符串

"""
生成随机的字符串 Token
"""

def get_random_str(username):
    import time, hashlib
    ctime = str(time.time())
    # print(ctime)
    # print(type(ctime))
    md5 = hashlib.md5(bytes(username, encoding="utf8"))
    md5.update(bytes(ctime, encoding="utf8"))
    # print(md5)
    # print(md5.hexdigest()) 获取md5的16进制字符串
    return md5.hexdigest()

get_random_str("alex")
原文地址:https://www.cnblogs.com/fenglingfu/p/14146348.html