Information: python official doc: "20.15. uuid - uuid objects according to rfc 4122 " uuid's Algorithm Introduction:" a universally unique identifier ( UUID) urn namespace "Overview: uuid is a 128-bit globally unique identifier, typically represented by a 32-byte string. it can guarantee the uniqueness of time and space, also known as the GUID, all called: UUID -- Universally Unique IDentifier Python called uuid guid. -- Globally Unique IDentifier c# GUID 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 ()--based on timestamp &nbThe sp; is generated by the MAC address, the current timestamp, and the random number. Global uniqueness is guaranteed, But the use of Mac also brings security problems, LAN can use IP instead of Mac. 2, Uuid2 ()--based on Distributed computing environment DCE (without this function in Python) The algorithm is the same as UUID1, and the difference is that the first 4 bits of the timestamp are replaced with the POSIX UID. This method is seldom used in practice. 3, UUID3 ()--MD5 hash value based on name by calculating the MD5 hash of the name and namespace, it is worthwhile to ensure the uniqueness of different names in the same namespace, and the uniqueness of different namespaces, But the same 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 out. 5, UUID5 ()--SHA-1 hash value based on name The algorithm is the same as UUID3, the difference is the use of secure hash algorithm 1 algorithm use aspects: first of all, Python is not based on DCE, so UUID2 can ignore; second, Uuid4 existence of probabilistic repetition, by no mapping, it is best not to; again, if in the global distributed computing environment, preferably with uuid1; Finally, If the uniqueness of the name requires, it is best to use UUID3 or UUID5. Coding Method: # -*- coding: utf-8 -*- import uuid name = "Test_name" namespace = "Test_ Namespace " print uuid.uuid1 () # method with parameters see python doc   PRINT UUID.UUID3 (Namespace, name) print uuid.uuid4 ()    PRINT UUID.UUID5 (Namespace, name)
Python generates a unique ID using the UUID library