SD_ID128_RANDOMIZE(3)

πŸ’… SD_ID128_RANDOMIZE(3) β€” sd_id128_randomize πŸ’…

okay bestie, so this page is all about sd_id128_randomize from the systemd manual set, and honestly? it's a little icon. it makes random 128-bit IDs and it does it flawlessly. let's get into it 🫢


✨ NAME ✨

sd_id128_randomize β€” generate 128-bit IDs. that's it. that's the whole job. and she ate πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <systemd/sd-id128.h>

int sd_id128_randomize(sd_id128_t *ret);

like, look at that signature. clean. minimal. main character energy fr fr.


🌸 DESCRIPTION 🌸

so sd_id128_randomize() generates a brand-new randomized 128-bit ID and hands it back to you in ret. every single time you invoke it, you get a new randomly generated ID β€” no reruns, no repeats, no cap. and how does it pull this off? it uses the getrandom(2) kernel random number generator. the kernel said "i got you" and it did πŸ’–

now, important detail, don't skip this one: sd_id128_randomize() always returns a UUID Variant 1 Version 4 compatible ID. which means it's literally guaranteed that this function will never return the ID made of all zero bits or all one bits β€” those are SD_ID128_NULL and SD_ID128_ALLF. so if you were sitting there worried about getting a cursed all-zeroes ID, girl, rest. it's not happening πŸ™ˆ

want more lore on the "sd_id128_t" type itself? go check sd-id128(3), she's got the whole backstory ✨

and ooh, also: the new command of systemd-id128(1) can be used as a command-line front-end for sd_id128_randomize(). so if you're a terminal kind of girlie instead of a C kind of girlie, you're covered πŸ¦‹


πŸ’œ RETURN VALUE πŸ’œ

the call returns 0 on success β€” and on success, ret gets filled in, slay β€” or a negative errno-style error code. simple as that πŸŽ€


⭐ NOTES ⭐

the functions described here are available as a shared library, which you can compile against and link to with the libsystemd pkg-config(1) file. standard linking ritual, nothing scary 🫢

⚠️ okay so listen: the code described here uses getenv(3), which is declared to be not multi-thread-safe. what that means for you is that the code calling the functions described here must not call setenv(3) from a parallel thread. like, do not do that. bestie please. 😭

the recommendation? only do calls to setenv() from an early phase of the program, back when no other threads have been started yet. get it out of the way early and then everyone's happy πŸ’–


🌈 HISTORY 🌈

sd_id128_randomize() was added in version 187. vintage. iconic. we love a long-running queen πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹

all the besties linked in the group chat, iykyk πŸ’…


and that's the whole page, babe β€” brought to you by systemd 261.3 on the SD_ID128_RANDOMIZE(3) page. go generate some wonderfully random IDs, you've got this πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from