The universally correct way to generate a UUID on a personal computer is uuid4, you should never use any other way except if specifically desired (Specific Desires shown below).
uuid4 is also guaranteed to be unique from UUID's generated from other computers.
In addition, uuid4 is currently cryptographically secure, meaning even if you expose your UUID's over the internet, the PRNG and entropy are strong enough to prevent others from guessing future UUID's you might generate. However, this is not guaranteed, so if cryptographic security matters for your application and you're handling sensitive user information, use secrets instead.
- Note that when using V1's timestamp and MAC, if your UUID's are exposed over the internet, people can easily guess future timestamps and you've already exposed your MAC, creating collisions.
This guarantee is based on the 122-bits of randomness in a UUID, making it of equivalent difficulty to hacking a Bitcoin wallet
- Version 1: UUIDs using timestamp and MAC Address.
- If you generate at the same timestamp, it will do +1
- Specific Desire: When looking through business logs, it can tell you when it was generated and what machine generated it.
- Version 2: Not Used
- Version 3: UUIDs based on the MD5 hash of given data. (Same as SHA1)
- Version 4: UUIDs with random data
- Specific Desire: You want the strongest guarantee of uniqueness and security.
- Version 5: UUIDs based on the SHA1 hash of given data.
- Specific Desire: When you want to be able to associate UUIDs with the "given data")
When you use V4, entropy is used to seed the PRNG. This includes timestamp, MAC address, and anything else collectible by the system (Internal RNG from CPU, Startup Time, Temperature readings, Disk Usage).
V1 is a kind of V4 where the only entropy is timestamp and MAC address and the PRNG is f(x) = x
Nuance into the discussion of urandom's security is here
uuid4s colliding are 1 in16**32.os.urandomand falls back to therandommodule. So, in conclusion, you should be safe. (Sorry for being overly specific, but I thought that might be interesting, for you or for the OP or someone else.)