41.21.1 UUID Generation

To generate UUIDs, call uuid-v4, uuid-v5 or uuid-v7. UUID v4 and v7 will by default use the normal elisp random for random numbers, but a different random number generator can be passed in, as long as it can be called with an arg of the end of the range of acceptable integers to generate (exclusive), and returns an integer.

Function: uuid-v4 &key rng

Return a uuid-v4 Lisp object representing a new UUIDv4. rng, if provided, is a function that will, when called with a numeric argument, return a random number between 0 and that number (exclusive).

Function: uuid-v7 &key rng

Similar to uuid-v4 but returns a uuid-v7, which is generated with a timestamp in addition to random numbers (generated from rng in a similar manner as uuid-v4).

These use random numbers, which should be cryptographically secure. See Random Numbers, but generally these random numbers are not sufficient to generate sufficiently random UUIDs. For private uses, the default behavior should be sufficient, but for professional uses, rng should be used, and provide cryptographically secure random numbers.

UUIDv5s must be created with a namespace and a name. The namespaces are defined in uuid-namespace-alist and are by default dns, url, oid, and x500.

Function: uuid-v5 namespace name

This function returns a new uuid-v5 Lisp object based on namespace, which is a symbol in the key of the uuid-namespace-alist: dns, url, oid, x500, or any symbol added. This is combined with name to construct a new UUIDv5.

An example is:

(uuid-v5 'dns "www.example.com")
Variable: uuid-namespace-alist

A list of namespace symbols and their corresponding UUIDs. Each alist entry is a cons of the symbol and a UUID Lisp object representing the namespace. This is used in uuid-v5, see above for more info on how this is used.