Information:
Official Python doc: "20.15." Uuid-uuid objects according to RFC 4122
UUID Algorithm Introduction: "A universally Unique IDentifier (UUID) URN Namespace"
Overview:
A UUID is a globally unique identifier of 128 bits, typically represented by a 32-byte string. It guarantees the uniqueness of time and space, also known as a GUID, all called:
uuid--universally Unique IDentifier Python called UUID
guid--globally Unique IDentifier C # called GUID
It guarantees the uniqueness of the generation ID by MAC address, timestamp, namespace, random number, pseudo-random number.
The UUID consists of five algorithms, which are five ways to achieve:
1, UUID1 ()--based on timestamp
Generated by MAC address, current timestamp, random number. 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)
The algorithm is the same as UUID1, the difference is to replace the first 4 bits of the timestamp 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.
5, UUID5 ()--SHA-1 hash value based on name
The algorithm is the same as UUID3, and the other is using the Secure Hash algorithm 1 algorithm
Terms of Use:
First of all, Python is not based on DCE, so UUID2 can be ignored;
Secondly, there is a probabilistic repetition of uuid4, which is not mapped and preferably not.
Thirdly, if 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.
Coding method:
# -*-coding:utf-8-*- import uuidname = " Test_name " namespace = " test_namespace " print uuid.uuid1 () # see python Doc print print Uuid.uuid4 () print uuid.uuid5 (namespace, name)
Python generates a unique ID using the UUID library