What is UUID (Universally Unique Identifier)? – POFTUT

What is UUID (Universally Unique Identifier)?


While developing applications or using services or mounting disks in Linux systems we may see the term UUID or 128-bit number which might seem interesting. UUID is a 128-bit number that is used to identify things like name, record, disk whatever we want.

Uniqueness Of UUID

What makes UUID so special or interesting is its uniqueness. Yes it is right  event two different and discrete systems creates UUID it is assumed both are unique and do not collide each other or with other UUID’s. Actually they are not perfectly unique but the probability of the collusion is very very very low to count.

Example UUID

Here are some UUID examples.

a8098c1a-f86e-11da-bd1a-00112444be1e

We can see that fstab content of the Linux systems contains UUID in order to identify the disk partition.

$ cat /etc/fstab
Example UUID
Example UUID

Generate UUID with Python

There are different ways to generate UUID. There is a lot of web-based UUID generators but using Python is more attractive. We can use Python uuid module to generate UUID with different options.

Generate UUID Based Host ID

While generating UUID we can make some part of UUID bound to the host. We will import uuid module and run uuid1() function in order to generate host-based UUID.

import uuid 
uuid.uuid1()
Generate UUID Based Host ID
Generate UUID Based Host ID

Generate Fully Random UUID

If we need to generate completely random UUID we need to call uuid4() function. Every time we call this function will create completely different UUIDs.

import uuid
uuid.uuid4()
Generate Fully Random UUID
Generate Fully Random UUID

LEARN MORE  How To Shuffle/Randomize Array in PHP

Leave a Comment