What is UUID or Universally Unique Identifier ?

UUID (universally unique identifier) is a 128 bit identifier value used in Software construction for uniquely indentifying some object or entity which doesn’t require central registration process.

Sometimes it is also referred as GUID ( Globally Unique Identifier). In canonical form for human readibility, it is represented by 36 character (32 alphanumberic character and 4 huphens). For example :

dd233d16-be05-11e6-b8fe-0401beb96201

According to RFC 4122 ( RFC is formal document from IETF – Internet Engineering Task Force), UUID can guarantee uniqueness across space and time. The chance of two UUID to become same is extremely low. Suppose if a machine generates one billion UUID every second for next 100 years, the probability of creating just one duplicate would be about 50%. Which in practical sense, makes two UUIDs very unique but not in theoratical sense.

Application of UUID

UUIDs are useful in many places such as identifiers for documents, hosts, application clients and other situation where a unique value is necessary like transaction IDs.

UUIDs were originally used in the Apollo Network Computing System and later in the Open Software Foundation’s (OSF) Distributed Computing Environment (DCE), and then in Microsoft Windows platform.

UUID Verisons

UUID has 5 variants. Each version takes different source of information to generate the UUID and are meant for specific purpose. For instance, Version 1 UUIDs takes date-time and MAC address, Version 2 UUIDs are generated from group or user id and date-time, Version 3 & 5 produces deterministic UUIDs generated from a user-specified namespace and user-supplied data, and Version 4 is randomly generated.

Generating a UUID in Python

import uuid
print uuid.uuid1()
print uuid.uuid4()
print uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
print uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')

References : https://tools.ietf.org/html/rfc4122.html

Note : This is a guest post by Ambuj Kumar. Recently, he also made an online tool that generates UUID for verion 1 and version 4 online : https://uuidgenerator.org/

Leave a comment

Your email address will not be published. Required fields are marked *