SoFunction
Updated on 2024-11-12

The simplest case of python uuid generating a unique id or str

Presentation:

A UUID is a 128-bit globally unique identifier, usually represented by a 32-byte string.

Use:

import uuid 
print uuid.uuid1()
14bfe806-f1c7-11e6-83b5-0680f3c45093

uuid1()--Generated based on MAC address, current timestamp, and random number.

import uuid
print uuid.uuid3(uuid.NAMESPACE_DNS, 'test') 
45a113ac-c7f2-30b0-90a5-a399ab912716

uuid3()-- Name-based MD5 hash.

import uuid
print uuid.uuid4()
8a602450-b27b-4d47-851d-3158da061153

uuid4()--Based on random numbers with some probability of repetition.

import uuid
print uuid.uuid5(uuid.NAMESPACE_DNS, 'test') 
4be0643f-1d98-573b-97cd-ca98a65347dd

uuid5()--name-based SHA-1 hash. Same usage as uuid3

Supplement:

No uuid2 function

Extension: Python generates unique IDs using haslib.md5

There are many cryptographic algorithms provided in the hashlib library's hash algorithm, sha1(), sha224(), sha256(), sha384(), sha512(), blake2b(), and blake2s(), md5(), and all of these methods return an object through the Unified Interface, for example, using sha256() can create a SHA-256 hash object.

import hashlib
md = haslib.md5(salt) # bytes
('') # encode
re = ()
print(re)

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more. If there is any mistake or something that has not been fully considered, please do not hesitate to give me advice.