---
name: "sd_id128_randomize"
section: "3"
platform: "linux"
package: "systemd-libs"
version: "262.1-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/sd_id128_randomize"
---

# sd\_id128\_randomize(3)

Generate 128-bit IDs

## NAME

sd\_id128\_randomize - Generate 128-bit IDs

## SYNOPSIS

```
#include <systemd/sd-id128.h>
```

**int sd\_id128\_randomize(sd\_id128\_t \****ret***);**

## DESCRIPTION

**sd\_id128\_randomize()** generates a new randomized 128-bit ID and returns it in *ret*. Every invocation returns a new randomly generated ID. This uses the [**getrandom**(2)](/getrandom/2.md) kernel random number generator.

Note that **sd\_id128\_randomize()** always returns a UUID Variant 1 Version 4 compatible ID. It is hence guaranteed that this function will never return the ID consisting of all zero or all one bits (**SD\_ID128\_NULL**, **SD\_ID128\_ALLF**).

For more information about the "sd\_id128\_t" type, see [**sd-id128**(3)](/sd-id128/3.md).

[**systemd-id128**(1)](/systemd-id128/1.md)'s **new** command may be used as a command line front-end for **sd\_id128\_randomize()**.

## RETURN VALUE

The call returns 0 on success (in which case *ret* is filled in), or a negative errno-style error code.

## NOTES

Functions described here are available as a shared library, which can be compiled against and linked to with the **libsystemd** [**pkg-config**(1)](/pkg-config/1.md) file.

The code described here uses [**getenv**(3)](/getenv/3.md), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not call [**setenv**(3)](/setenv/3.md) from a parallel thread. It is recommended to only do calls to **setenv()** from an early phase of the program when no other threads have been started.

## HISTORY

**sd\_id128\_randomize()** was added in version 187.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-id128**(3)](/sd-id128/3.md), [**machine-id**(5)](/machine-id/5.md), [**getrandom**(2)](/getrandom/2.md), [**random**(4)](/random/4.md), [**sd\_id128\_get\_machine**(3)](/sd_id128_get_machine/3.md)
