Httprunner practice two--parameterized generation UUID

Source: Internet
Author: User
Tags md5 hash unique id

Interface test, you need to use the UUID, which is used to generate a unique ID.

1. What is a UUID?

A UUID is a globally unique identifier of 128 bits, typically represented by a 32-byte string. It guarantees the uniqueness of time and space, also known as the GUID, called the UUID in the uuid--universally unique Identifier,python.
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.

      • UUID1 ()--based on timestamp. Generated by MAC address, current timestamp, random number. can guarantee uniqueness globally, but the use of Mac also brings security problems, LAN can use IP instead of Mac.
      • UUID3 ()--MD5 hash value based on the name. By calculating the MD5 hash of the name and namespace, it is worthwhile to ensure the uniqueness of different names in the same namespace, and the uniqueness of different namespaces, but the same name of the same namespace produces the same UUID.
      • Uuid4 ()--based on random numbers. obtained by pseudo-random number, there is a certain repetition probability, the probability can be calculated.
      • UUID5 ()--SHA-1 hash value based on the name. The algorithm is the same as UUID3, and the other is using the Secure Hash algorithm 1 algorithm.
2. Basic usage
1 ImportUUID2 3 Print(Uuid.uuid1 ())#UUID based on the computer host ID and the current time "4 Print(UUID.UUID3 (UUID). Namespace_dns,'python'))#MD5-encrypted UUID based on namespaces and one character5 Print(Uuid.uuid4 ())#randomly generate a UUID6 Print(UUID.UUID5 (UUID). Namespace_dns,'python'))#SHA-1-encrypted UUID based on namespaces and one character7 Print(UUID.) UUID ('{00010203-0405-0607-0809-0a0b0c0d0e0f}'))#generate UUID based on hexadecimal characters
3. Common Application Scenarios

Python generates the UUID and removes the middle '-'

Take Uuid4 () as an example

1 #Coding=utf-82 ImportUUID3 4 defgen_uuid4 ():5S_uuid =Str (UUID.UUID4 ())6L_uuid = S_uuid.split ('-')7S_uuid ="'. Join (L_UUID)8     returnS_uuid9 Ten Print(Gen_uuid4 ())

Httprunner practice two--parameterized generation UUID

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.