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:UUIDis 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 # called GUID it guarantees generation by MAC address, timestamp, namespace, random number, pseudo-random number The uniqueness of the ID. 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 the 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 by calculating the name and namespace of the MD5 hash is worthwhile, guaranteeing the uniqueness of different names in the same namespace, and the uniqueness of different namespaces, but the same name of the same namespace generates the same 's UUID. 4, Uuid4 ()--based on the random number from the pseudo-random number obtained, 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 using Secure Hash algorithm 1 algorithm usage: First of all, Python is not based on DCE, so UUID2 can suddenly Second, uuid4 existence 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 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