Python's UUID module

Source: Internet
Author: User

I. INTRODUCTION

A UUID is a globally unique identifier of 128 bits, usually represented by a 32-byte alphabetic string. It can guarantee the uniqueness of time and space, also known as the GUID.

All called: uuid--universally unique IDentifier is called a UUID in Python and is called the guid--globally unique IDentifier 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, that is, five ways to achieve.

(1). UUID1 ()---timestamp-based

Generated by the MAC address, current timestamp, random number. can guarantee uniqueness on a global scale. But because the use of MAC addresses also poses a security problem,

IP can be used instead of Mac in LAN.

(2). UUID2 ()---Based on distributed computing environment DCE (without this function in Python)

The algorithm and the UUID1 are the same, the difference is that the timestamp of the first 4 bits of the POSIX uid, in practice rarely used in this method.

(3). UUID3 ()---Based on name and MD5 hash value

By calculating the MD5 hash of the name and namespace, it is worthwhile to ensure that the uniqueness of different names in the same namespace, and the uniqueness of different namespaces,

But the 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 ()---name-based SHA-1 hash value

The algorithm is the same as UUID3 (), and the difference is using the secure Hash algorithm 1 algorithm.

Usage Experience:

    1. There is no DCE-based in Python, so uuid2 can ignore
    2. Uuid4 There is a probabilistic repetition, by no mapping, preferably without
    3. If you are in a distributed computing environment at Global, it is best to use UUID1
    4. If the uniqueness of the name is required, it is best to use UUID3 or UUID5

Two. Use
Import uuid# uuid1 () >>> print (UUID.UUID1 ()) 2cf0fa7e-48d9-11e6-93fb-c03fd53413ef# uuid3 () >>> Print (UUID.UUID3 (UUID). Namespace_dns, ' Test ')) 45a113ac-c7f2-30b0-90a5-a399ab912716# uuid4 () >>> print (Uuid.uuid4 ()) 08bffbb6-05e1-41c1-8989-6aa07a4a5e5d# uuid5 () >>> print (UUID. UUID.UUID5 Namespace_dns, ' test ') 4be0643f-1d98-573b-97cd-ca98a65347dd

  

Python's UUID module

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.