Python module-uuid__python

Source: Internet
Author: User
UUID (i) Introduction

The UUID is a 128-bit globally unique identifier, typically represented by a 32-byte string (hexadecimal). He can indicate the uniqueness of time and space, also known as GUIDs. (b) five major algorithms 1, uuid1 ()

is a timestamp based on the MAC address, timestamp, random number generation, he can ensure global uniqueness, due to the use of MAC address security issues, LAN can use IP to replace MVC.

Print Uuid.uuid1 ()   # eac806b5-21fc-11e8-8c23-c4b301c5d3d1
print uuid.uuid1 (). int  # 78492418116412030302116828568130802641
Print uuid.uuid1 (). bytes  # o!? IJ
Print Uuid.uuid1 (). Hex  # cd6f96ae21fe11e885b2c4b301c5d3d1
print Uuid.uuid1 (). Fields  # (3781522910L, 8702L, 4584L, 158L, 201L, 216273107932113L)
2, Uuid2 ()

Based on a distributed computing environment DCE (not in Python), the algorithm is essentially the same as UUID1, with the difference being to replace the first 4 bits of the timestamp with the POSIX uid. 3, UUID3 ()

The MD5 hash value based on the name, which is worthwhile by calculating the MD5 hash of the name and namespace, guarantees 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 UUID.

Import UUID

name = "Loco_python"
namespace = uuid.uuid1 ()

Print type (namespace)
print uuid.uuid3 ( Namespace=namespace, Name=name)

# # #输出结果:
<class ' uuid. UUID ' >
9040b1fa-cbf0-3e81-abfa-f713883c924e
4, Uuid4 ()

Based on the random number, the pseudo random number is obtained, and there is a certain probability of repetition, which can be calculated.

Print Uuid.uuid4 ()  # f09ce61b-1f67-43f0-96be-bbc46ab32949
5, UUID5 ()

Based on the name of the SHA-1 hash value, the algorithm is the same as UUID3, the difference is the use of the Secure hash Algorithm 1 algorithm.

Import UUID
name = "Loco_python"
namespace = Uuid.uuid1 ()
# cd94d9f8-349b-5661-87b1-7131888055c0
Print UUID.UUID5 (namespace=namespace, Name=name)

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.