In a comment, you mention that you are using Python and link to this. If you, for some reason, absolutely need to generate your own, then at least have the good sense to stay away from generating v1 and v2 UUIDs. For example, in Windows, there is CoCreateGuid or UuidCreate or one of the various wrappers available from the numerous frameworks in use. But a better one is this: "Well, before I answer, can you tell us why you need to code up your own UUID generation algorithm instead of calling the UUID generation functionality that most modern operating systems provide?"ĭoing that is easier and safer, and since you probably don't need to generate your own, why bother coding up an implementation? In that case, the answer becomes use whatever your O/S, programming language or framework provides. One answer is: "it depends what kind of UUID you wish to generate". For a set of random numbers: chance_of_collision = 1 - (set_size! / (set_size - tries)!) / (set_size ^ tries) It would belong in a RFC about generating randomness. In that situation, I don't think that algorithm belongs in a RFC describing methods for generating unique values. If that is true, than you have a very GOOD chance of two machines in the world eventually creating the same "UUID"v4 (quotes because there isn't a mechanism for guaranteeing U.niversal U.niqueness). from reading RFC4122, it looks like that version does NOT eliminate possibility of collisions. To be honest, I don't understand why UUIDv4 exists. This is appropriate for a transaction ID (even if everyone is doing millions of transactions/s). UUIDv1 uses the current timestamp, plus a machine identifier, plus some random-ish stuff to make a number that will never be generated by that algorithm again. It is meant to be UNIQUE, not un-guessable. If you want a unique identifier with effectively 0.00.many more 0s here.001% chance of collision, you should use UUIDv1. If you want a random number, use a random number library. This is the more secure and generally recommended version. Version 5: This generates a unique ID from an SHA-1 hash of a namespace and name. If are dealing with very strict resource requirements (e.g. Version 3: This generates a unique ID from an MD5 hash of a namespace and name. If you are interacting with other systems, this choice was already made and you should check with version and namespaces they use. If you need to generate reproducible UUIDs from given names, you want a version 3 or version 5. The advantage of this version is that when you're debugging and looking at a long list of information matched with UUIDs, it's quicker to spot matches. If you just need to generate a UUID, this is probably what you want. Version 4: These are generated from random (or pseudo-random) numbers. The advantage of this version is that, while looking at a list of UUIDs generated by machines you trust, you can easily know whether many UUIDs got generated by the same machine, or infer some time relationship between them. If any of these things is sensitive in any way, don't use this. Version 1: This generates a unique ID based on a network card MAC address and current time. If you just need a unique ID, you want a version 1 or version 4. There are two different ways of generating a UUID.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |