What are UUIDs?
- UUID stands for Universally Unique Identifier.
- A UUID is a 128-bit number used to uniquely identify some object or entity on the Internet.
- In its canonical form, a UUID is represented by 32 lowercase hexadecimal digits, displayed in five groups separated by hyphens. The pattern is 8-4-4-4-12, resulting in a 36 character string (including hyphens).
- Example:
550e8400-e29b-41d4-a716-446655440000
. - It is designed to be sufficiently random such that the probability of collision (two different inputs producing the same output) is extremely low.
Benefits of UUIDs
- The primary advantage of UUIDs is that they can be generated in any location by any system without requiring central coordination while still being able to assert uniqueness across the entire universe.
- It can be used to assign unique identifiers in a system without the need for a central authority to avoid collisions.
- UUIDs are preferable over traditional sequential IDs in a multi-server setup where coordination can be complex and time-consuming.
How to Install uuidgen
uuidgen
is typically included in the uuid-runtime
package in Debian and most other Linux distributions. You can install it using the package manager apt
.
Run the following command to install uuidgen
:
After the installation, you should be able to generate UUIDs by typing uuidgen
in your terminal. Each call will produce a new, random UUID.
Example output:
Remember, UUIDs generated are pseudo-random and there are different versions of UUIDs, based on the method of generation. uuidgen
typically generates UUIDs using either random numbers (Version 4) or the current time and the machine’s MAC address (Version 1).
Generating UUIDs in Python
In Python, you can use the uuid
library to generate UUIDs. The uuid4()
function generates a random UUID. The randomness is based on random numbers from the random number generator in your system, which makes the probability of collision negligible.