Python generates a unique ID using the UUID library

Source: Internet
Author: User
Tags md5 hash repetition unique id uuid

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

Related Article

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.