Universal Unique ID--uuid (Python)

Source: Internet
Author: User

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:

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.