Original link: http://www.cnblogs.com/dkblog/archive/2011/10/10/2205200.html
Information: Python official doc: "20.15." Uuid-uuid objects according to RFC 4122 "UUID 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 guarantees the uniqueness of time and space, also called the GUID, called the UUID in uuid--universally unique IDentifier Python Guid--global Ly Unique IDentifier called GUID 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, namely five methods to achieve: 1 , UUID1 ()--based on the time stamp by the MAC address, the current timestamp, random number generation. can guarantee uniqueness globally, 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) is the same as UUID1, unlike 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 it is worthwhile to calculate the MD5 hash of the name and namespace, which guarantees the uniqueness of different names in the same namespace, and the uniqueness of different namespaces, but the same namespace The name generates the same UUID. 4 , Uuid4 ()--based on the random number is obtained by pseudo-random number, there is a certain repetition probability, the probability can be calculated. 5, UUID5 ()--the name-based SHA 1 hash value algorithm is the same as UUID3, the difference is the use of Secure Hash algorithm 1 algorithm usage: First, Python is not based on DCE, so UUID2 can ignore Second, Uuid4 exists probabilistic repetition, by no mapping, preferably not, again, if in the global distributed computing environment, it is best to use UUID1; Finally, if the uniqueness of the name requires, it is best to use UUID3 or UUID5. Encoding method:
# -*-coding:utf-8-*- Import UUID " test_name " "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