Almost there:

uuid.UUID(int=rd.getrandbits(128), version=4)

This was determined with the help of help:

>>> help(uuid.UUID.__init__)
Help on method __init__ in module uuid:

__init__(self, hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None) unbound uuid.UUID method
    Create a UUID from either a string of 32 hexadecimal digits,
    a string of 16 bytes as the 'bytes' argument, a string of 16 bytes
    in little-endian order as the 'bytes_le' argument, a tuple of six
    integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version,
    8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as
    the 'fields' argument, or a single 128-bit integer as the 'int'
    argument.  When a string of hex digits is given, curly braces,
    hyphens, and a URN prefix are all optional.  For example, these
    expressions all yield the same UUID:
    
    UUID('{12345678-1234-5678-1234-567812345678}')
    UUID('12345678123456781234567812345678')
    UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
    UUID(bytes='\x12\x34\x56\x78'*4)
    UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
                  '\x12\x34\x56\x78\x12\x34\x56\x78')
    UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
    UUID(int=0x12345678123456781234567812345678)
    
    Exactly one of 'hex', 'bytes', 'bytes_le', 'fields', or 'int' must
    be given.  The 'version' argument is optional; if given, the resulting
    UUID will have its variant and version set according to RFC 4122,
    overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'.
Answer from Alex Hall on Stack Overflow
Top answer
1 of 10
68

Almost there:

uuid.UUID(int=rd.getrandbits(128), version=4)

This was determined with the help of help:

>>> help(uuid.UUID.__init__)
Help on method __init__ in module uuid:

__init__(self, hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None) unbound uuid.UUID method
    Create a UUID from either a string of 32 hexadecimal digits,
    a string of 16 bytes as the 'bytes' argument, a string of 16 bytes
    in little-endian order as the 'bytes_le' argument, a tuple of six
    integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version,
    8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as
    the 'fields' argument, or a single 128-bit integer as the 'int'
    argument.  When a string of hex digits is given, curly braces,
    hyphens, and a URN prefix are all optional.  For example, these
    expressions all yield the same UUID:
    
    UUID('{12345678-1234-5678-1234-567812345678}')
    UUID('12345678123456781234567812345678')
    UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
    UUID(bytes='\x12\x34\x56\x78'*4)
    UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
                  '\x12\x34\x56\x78\x12\x34\x56\x78')
    UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
    UUID(int=0x12345678123456781234567812345678)
    
    Exactly one of 'hex', 'bytes', 'bytes_le', 'fields', or 'int' must
    be given.  The 'version' argument is optional; if given, the resulting
    UUID will have its variant and version set according to RFC 4122,
    overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'.
2 of 10
30

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
🌐
Proinsias
proinsias.github.io › til › Python-UUID-generate-random-but-reproducible-with-seed
Python: Generate random but reproducible UUID with seed - Looking for data in all the right places…
May 13, 2025 - import uuid import random seed = 0 rd = random.Random() rd.seed(seed) reproducible_seed = uuid.UUID(int=rd.getrandbits(128))
Discussions

random uuid with seed
Is there a reason why you are using UUIDs in the first place? Thinking you could just set seed and do randomization with numbers to get deterministic names. E.g line 177 in dashboard_methods.py if ... More on github.com
🌐 github.com
7
January 12, 2021
How to generate a random UUID which is reproducible (with a seed) in Python
The uuid4() function of Python’s module uuid generates a random UUID, and seems to generate a different one every time: I would like to be able to generate the same random UUID every time I run a script – that is, I’d like to seed the random generator in uuid4(). Is there a way to do this? More on python.tutorialink.com
🌐 python.tutorialink.com
1
Not possible to seed uuid4
The solution is pretty much given in: http://stackoverflow.com/questions/41186818/how-to-generate-a-random-uuid-which-is-reproducible-with-a-seed-in-python More on github.com
🌐 github.com
16
March 17, 2017
UUID are not unique?
We followed the instructions to generate UUIDs. It worked for awhile, and then we got to around 4,900 records in the table, the UUID was no longer unique for a particular record. We were able to catch this because we set… More on community.getgrist.com
🌐 community.getgrist.com
0
0
July 27, 2022
🌐
Reddit
reddit.com › r/learnprogramming › uuid v4 and seeds
r/learnprogramming on Reddit: UUID v4 and Seeds
August 6, 2023 -

I've been learning about UUIDs and have a few questions about version 4 implementation.

I understand that the likelihood of generating the same UUID is incredibly small, but is that likelihood jeopardized at all by the random number generator and seed used? Maybe the likelihood of using the same seed is incredibly small too, so how does one go about choosing a good seed? I'm thinking about this from the perspective of someone implementing their own UUID generator. I assume that the libraries available have good implementations.

I guess the question I'm really asking is this, when implementing a version 4 UUID generator how does one avoid seed related issues creating duplicate UUIDs?

Thanks!

🌐
Python
docs.python.org › 3 › library › uuid.html
uuid — UUID objects according to RFC 9562 — Python 3.14.3 ...
February 23, 2026 - >>> import uuid >>> # make a UUID based on the host ID and current time >>> uuid.uuid1() UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') >>> # make a UUID using an MD5 hash of a namespace UUID and a name >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org') UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e') >>> # make a random UUID >>> uuid.uuid4() UUID('16fd2706-8baf-433b-82eb-8c7fada847da') >>> # make a UUID using a SHA-1 hash of a namespace UUID and a name >>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org') UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d') >>> # make a UUID from a string of hex digits (braces an
🌐
pablosanjose
pablosanjose.com › generating-deterministic-uuids-in-python
Generating Deterministic UUIDs in Python - pablosanjose.com
September 17, 2021 - As the text can be arbitrarily long, we first hash the text and then use the hash to form the seed. import hashlib import random import uuid class IDGeneratorV2: def __init__(self) -> None: self.random: random.Random = random.Random() def get(self, text: str) -> str: h = hashlib.sha224(text.encode("utf-8")) self.random.seed(int(h.hexdigest(), 16)) return uuid.UUID(version=4, int=self.random.getrandbits(128)).hex
🌐
GitHub
github.com › oegedijk › explainerdashboard › issues › 69
random uuid with seed · Issue #69 · oegedijk/explainerdashboard
January 12, 2021 - Is there a reason why you are using UUIDs in the first place? Thinking you could just set seed and do randomization with numbers to get deterministic names. E.g line 177 in dashboard_methods.py if not hasattr(self, "name") or self.name i...
Author   oegedijk
🌐
PYnative
pynative.com › home › python › random › python uuid module to generate universally unique identifiers
Python UUID Module to Generate Universally Unique Identifiers [Guide]
March 9, 2021 - Python UUID module to generate the universally unique identifiers. Generate a version 1, 3, 4, and 5 UUIDs. secure random UUID. String to UUID and UUId to String. why and when use UUID.Structure of UUID. Safe and Unsafe UUID
🌐
Python Module of the Week
pymotw.com › 2 › uuid
uuid – Universally unique identifiers - Python Module of the Week
Some attributes, such as hex, int, and urn, are different representations of the UUID value. $ python uuid_uuid1.py 2500b32e-7c1b-11e2-830a-70cd60f2c980 <class 'uuid.UUID'> bytes : '%\x00\xb3.|\x1b\x11\xe2\x83\np\xcd`\xf2\xc9\x80' hex : 2500b32e7c1b11e2830a70cd60f2c980 int : 49185070078265283276219513639424674176 urn : urn:uuid:2500b32e-7c1b-11e2-830a-70cd60f2c980 variant : specified in RFC 4122 version : 1 fields : (620802862L, 31771L, 4578L, 131L, 10L, 124027397130624L) time_low : 620802862 time_mid : 31771 time_hi_version : 4578 clock_seq_hi_variant: 131 clock_seq_low : 10 node : 124027397130624 time : 135807394801300270 clock_seq : 778
Find elsewhere
🌐
GitHub
github.com › joke2k › faker › issues › 484
Not possible to seed uuid4 · Issue #484 · joke2k/faker
March 17, 2017 - It is not possible to seed the uuid4 property. >>> f1 = Faker() >>> f1.seed(4321) >>> print(f1.uuid4()) 4a6d35db-b61b-49ed-a225-e16bc164f7cc >>> f2 = Faker() &gt...
Author   J535D165
🌐
UUID Generator
uuidgenerator.net › dev-corner › python
Generate a UUID in Python
Although it's rare, in some circumstances you might need to convert from a string (like the one generated on line #5 above) or byte representation of a UUID back into an instance of UUID. Python's uuid module provides for this scenario with the constructor method, uuid.UUID.
🌐
PyPI
pypi.org › project › shortuuid
shortuuid · PyPI
Often, one needs to use non-sequential IDs in places where users will see them, but the IDs must be as concise and easy to use as possible. shortuuid solves this problem by generating uuids using Python's built-in uuid module and then translating them to base57 using lowercase and uppercase letters and digits, and removing similar-looking characters such as l, 1, I, O and 0.
      » pip install shortuuid
    
Published   Mar 11, 2024
Version   1.0.13
🌐
GeeksforGeeks
geeksforgeeks.org › generating-random-ids-using-uuid-python
Generating Random id's using UUID in Python - GeeksforGeeks
April 4, 2025 - We had discussed the ways to generate unique id's in Python without using any python inbuilt library in Generating random Id’s in Python · In this article we would be using inbuilt functions to generate them. A UUID is 128 bits in total, but uuid4() provides 122 bits of randomness due to version and variant bits.
🌐
Javatpoint
javatpoint.com › how-to-generate-uuid-in-python
How to Generate UUID in Python - Javatpoint
How to Generate UUID in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
🌐
pythontutorials
pythontutorials.net › blog › how-to-generate-a-random-uuid-which-is-reproducible-with-a-seed-in-python
How to Generate a Seeded, Reproducible Random UUID in Python — pythontutorials.net
Supporting distributed systems where multiple nodes need to agree on UUIDs derived from a shared seed. Python’s uuid.uuid4() (from the uuid module) generates UUID4s by:
🌐
GeeksforGeeks
geeksforgeeks.org › generating-hash-ids-using-uuid3-and-uuid5-in-python
Generating hash id's using uuid3() and uuid5() in Python - GeeksforGeeks
May 21, 2024 - uuid module defines the following namespace identifiers for use with uuid3() or uuid5() : NAMESPACE_DNS : Used when name string is fully qualified domain name. NAMESPACE_URL : Used when name string is a URL. NAMESPACE_OID : Used when name string is an ISO OID. NAMESPACE_X500 : Used when name string is an X.500 DN in DER or a text output format. ... # Python3 code to demonstrate working # of uuid3() and uuid5() import uuid # initializing a string url = "https://www.geeksforgeeks.org/fibonacci-sum-subset-elements/" # using NAMESPACE_URL as namespace # to generate MD5 hash uuid print ("The MD5 hash value generated ID is : ", uuid.uuid3(uuid.NAMESPACE_URL, url)) # using NAMESPACE_URL as namespace # to generate SHA-1 hash uuid print ("The SHA-1 hash value generated ID is : ", uuid.uuid5(uuid.NAMESPACE_URL, url))
🌐
Grist Creators
community.getgrist.com › ask for help
UUID are not unique? - Ask for Help - Grist Creators
July 27, 2022 - We followed the instructions to generate UUIDs. It worked for awhile, and then we got to around 4,900 records in the table, the UUID was no longer unique for a particular record. We were able to catch this because we set…
🌐
Real Python
realpython.com › ref › stdlib › uuid
uuid | Python Standard Library – Real Python
>>> import uuid >>> uuid.uuid3(uuid.NAMESPACE_DNS, "python.org") UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')