UUID_GENERATE(3)

🌸 UUID_GENERATE(3) 🌸

okay bestie, so this is a page from the Programmers Manual β€” it's the libuuid girlies' guide to making brand-new UUIDs. like, literally creating unique identifiers out of thin air. it's giving ✨main character energy✨ and you're gonna love her.


✨ NAME ✨

uuid_generate, uuid_generate_random, uuid_generate_time, uuid_generate_time_safe β€” create a new unique UUID value πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

#include <uuid.h>

void uuid_generate(uuid_t out);
void uuid_generate_random(uuid_t out);
void uuid_generate_time(uuid_t out);
int uuid_generate_time_safe(uuid_t out);
void uuid_generate_md5(uuid_t out, const uuid_t ns, const char *name,
size_t len);
void uuid_generate_sha1(uuid_t out, const uuid_t ns, const char *name,
size_t len);

πŸ’– DESCRIPTION πŸ’–

So uuid_generate() makes a new universally unique identifier (a UUID, iykyk). The uuid gets generated based on high-quality randomness from getrandom(2), /dev/urandom, or /dev/random if those are available. But if high-quality randomness isn't available? Then uuid_generate() falls back to an alternative algorithm that uses the current time, the local ethernet MAC address (if available), and random data from a pseudo-random generator. slay, she has a backup plan πŸ’…

uuid_generate_random() forces the all-random UUID format β€” even if there's no high-quality random number generator available, in which case a pseudo-random generator gets substituted in. ngl, watch out: using a pseudo-random generator may compromise the uniqueness of UUIDs generated this way. πŸ’€

uuid_generate_time() forces the alternative algorithm β€” the one that uses the current time and the local ethernet MAC address (if available). Okay so here's the lore: this algorithm used to be the default for generating UUIDs, but because it uses the ethernet MAC address, it can leak information about when and where the UUID was generated. that's a privacy problem in some applications, fr fr. so uuid_generate() only reaches for this algorithm if a high-quality source of randomness isn't available. πŸ™ˆ

To guarantee uniqueness of UUIDs generated by concurrently running processes, the uuid library uses a global clock state counter (if the process has permissions to gain exclusive access to this file) and/or the uuidd(8) daemon β€” if it's already running, or can be spawned by the process (if installed and the process has enough permissions to run it). If neither of these two synchronization mechanisms can be used, it is theoretically possible that two concurrently running processes obtain the same UUID(s). to tell whether the UUID was generated in a safe manner, use uuid_generate_time_safe. 🫢

uuid_generate_time_safe() is basically uuid_generate_time()'s twin, except it returns a value that tells you whether any of the synchronization mechanisms (the ones above ⬆️) got used. iconic.

The UUID is 16 bytes (128 bits) long, which gives approximately 3.4x10^38 unique values. and for scale? there are approximately 10^80 elementary particles in the universe according to Carl Sagan's Cosmos. πŸͺ so yeah, the new UUID can reasonably be considered unique among all UUIDs created on the local system, and among UUIDs created on other systems in the past and in the future. no cap.

The uuid_generate_md5() and uuid_generate_sha1() functions generate an MD5 and SHA1 hashed (predictable) UUID based on a well-known UUID providing the namespace plus an arbitrary binary string. These UUIDs conform to V3 and V5 UUIDs per RFC-4122 β€” https://tools.ietf.org/html/rfc4122 🌈


⭐ RETURN VALUE ⭐

The newly created UUID is returned in the memory location pointed to by out.

uuid_generate_time_safe() returns zero if the UUID has been generated in a safe manner, and -1 otherwise. πŸŽ€


πŸ‘‘ CONFORMING TO πŸ‘‘

This library generates UUIDs compatible with OSF DCE 1.1, plus hash based UUIDs V3 and V5 compatible with RFC-4122 β€” https://tools.ietf.org/html/rfc4122 ✨


πŸ¦‹ AUTHORS πŸ¦‹

Theodore Y. Ts'o πŸ’œ


🌸 SEE ALSO 🌸


πŸ’€ REPORTING BUGS πŸ’€

For bug reports, use the issue tracker: https://github.com/util-linux/util-linux/issues

like, please do tell them β€” they wanna know 🫢


🌈 AVAILABILITY 🌈

The libuuid library is part of the util-linux package since version 2.15.1. It can be downloaded from the Linux Kernel Archive: https://www.kernel.org/pub/linux/utils/util-linux/ ⭐


and that's the whole page bestie πŸŽ€ this one's from util-linux 2.41.6, dated 2026-08-31 β€” go forth and generate responsibly, mwah πŸ’…πŸ’–

πŸ“¦ where this page comes from