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

前端 未结 6 1454
暗喜
暗喜 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:51

    Faker makes this easy

    >>> from faker import Faker
    >>> f1 = Faker()
    >>> f1.seed(4321)
    >>> print(f1.uuid4())
    cc733c92-6853-15f6-0e49-bec741188ebb
    >>> print(f1.uuid4())
    a41f020c-2d4d-333f-f1d3-979f1043fae0
    >>> f1.seed(4321)
    >>> print(f1.uuid4())
    cc733c92-6853-15f6-0e49-bec741188ebb
    

提交回复
热议问题