I. INTRODUCTION
A UUID is a globally unique identifier of 128 bits, usually represented by a 32-byte alphabetic string. It can guarantee the uniqueness of time and space, also known as the GUID.
All called: uuid--universally unique IDentifier is called a UUID in Python and is called the guid--globally unique IDentifier in C #.
It guarantees the uniqueness of the generation ID by MAC address, timestamp, namespace, random number, pseudo-random number.
UUID mainly has five algorithms, that is, five ways to achieve.
(1). UUID1 ()---timestamp-based
Generated by the MAC address, current timestamp, random number. can guarantee uniqueness on a global scale. But because the use of MAC addresses also poses a security problem,
IP can be used instead of Mac in LAN.
(2). UUID2 ()---Based on distributed computing environment DCE (without this function in Python)
The algorithm and the UUID1 are the same, the difference is that the timestamp of the first 4 bits of the POSIX uid, in practice rarely used in this method.
(3). UUID3 ()---Based on name and MD5 hash value
By calculating the MD5 hash of the name and namespace, it is worthwhile to ensure that the uniqueness of different names in the same namespace, and the uniqueness of different namespaces,
But the name of the same namespace produces the same UUID.
(4). UUID4 ()---based on random numbers
obtained by pseudo-random number, there is a certain repetition probability, the probability can be calculated.
(5). UUID5 ()---name-based SHA-1 hash value
The algorithm is the same as UUID3 (), and the difference is using the secure Hash algorithm 1 algorithm.
Usage Experience:
- There is no DCE-based in Python, so uuid2 can ignore
- Uuid4 There is a probabilistic repetition, by no mapping, preferably without
- If you are in a distributed computing environment at Global, it is best to use UUID1
- If the uniqueness of the name is required, it is best to use UUID3 or UUID5
Two. Use
Import uuid# uuid1 () >>> print (UUID.UUID1 ()) 2cf0fa7e-48d9-11e6-93fb-c03fd53413ef# uuid3 () >>> Print (UUID.UUID3 (UUID). Namespace_dns, ' Test ')) 45a113ac-c7f2-30b0-90a5-a399ab912716# uuid4 () >>> print (Uuid.uuid4 ()) 08bffbb6-05e1-41c1-8989-6aa07a4a5e5d# uuid5 () >>> print (UUID. UUID.UUID5 Namespace_dns, ' test ') 4be0643f-1d98-573b-97cd-ca98a65347dd
Python's UUID module