First, overview:
The abbreviation for the UUID (universally unique Identity) is a software-constructed standard, typically represented by a 32-byte 16 binary number (128-bit), which guarantees the uniqueness of time and space. Currently the most widely used UUID is Microsoft's GUIDs.
Second, the role:
The UUID allows all elements of the distributed system to have unique identification information so that everyone can create a different uuid from others, regardless of the name duplication problem when the database is established. Randomly generate strings, as tokens, user accounts, orders, and so on.
Three, the principle:
A UUID is a number generated on a machine that guarantees that all machines in the same space and time are unique.
The UUID is composed of the following parts:
(1) Timestamp: Generates a string based on the current time or clock sequence
(2) The only machine identification number, according to the network card MAC address or IP access, if there is no network card is obtained in other ways.
(3) Random number: Machine automatically randomly set sequence
Wait a minute
Four, the algorithm
The UUID has 5 generation algorithms, namely UUID1 (), Uuid2 (), UUID3 (), Uuid4 (), and UUID5 ().
1, UUID1 () timestamp-based
By MAC address, current timestamp, random number. To ensure uniqueness on a global scale. However, due to the use of MAC address security problems, the use of IP in LAN instead of Mac
2, Uuid2 () based on the distributed environment DCE
The algorithm and the UUID1 are the same, the difference is to change the pre-timestamp four bits into the Poix uid, the actual rarely used. Note: This function is not in Python
3, UUID3 () based on the name and MD5 hash value
By calculating the MD5 hash of the name and namespace, the uniqueness of different names in the same namespace and the uniqueness of different namespaces are ensured. But the same name in the same namespace produces the same UUID.
4, Uuid4 () based on random number
obtained by pseudo-random number, there is a certain repetition probability, this probability can be calculated
5, UUID5 () based on name and Sahi value
The algorithm and the UUID3 are the same, the difference is using the Sahi algorithm
Five, the use of experience:
1. There is no DCE in Python, so uuid2 can ignore
2, Uuid4 existence probability repeatability, because of no mapping, it is best not to use
3, if the global distributed environment, it is best to use UUID1
4, if the uniqueness of the name requirements, it is best to use UUID3 or UUID5
Vi. Use of: