How to generate a random UUID which is reproducible (with a seed) in Python

前端 未结 6 1457
暗喜
暗喜 2020-12-15 14:57

The uuid4() function of Python\'s module uuid generates a random UUID, and seems to generate a different one every time:

In [1]: import uuid

In          


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 15:44

    This is based on a solution used here:

    import hashlib
    import uuid
    
    m = hashlib.md5()
    m.update(seed.encode('utf-8'))
    new_uuid = uuid.UUID(m.hexdigest())
    

提交回复
热议问题