Skip to content

uuid

Generates a Universally Unique Identifier (UUID) string.

uuid([version=string]) -> string

The uuid function generates a Universally Unique Identifier (UUID) string. UUIDs, 128-bit numbers, uniquely identify information in computer systems.

This function generates several UUID versions based on relevant standards like RFC 4122 and the newer RFC 9562 which defines versions 6 and 7.

Specifies the version of the UUID to generate. If you omit this argument, the function uses "v4" by default. It supports the following values:

  • "v1": Generates a time-based UUID using a timestamp and node ID.
  • "v4": Generates a randomly generated UUID using a cryptographically strong random number generator (see RFC 4122). This is the default.
  • "v6": Generates a time-based UUID, similar to v1 but reordered for better database index locality and lexical sorting (see RFC 9562).
  • "v7": Generates a time-based UUID using a Unix timestamp and random bits, designed to be monotonically increasing (suitable for primary keys, see RFC 9562).
  • "nil": Generates the special “nil” UUID, which consists entirely of zeros: 00000000-0000-0000-0000-000000000000.

Defaults to "v4".

from {guid: uuid()}
{guid: "f47ac10b-58cc-4372-a567-0e02b2c3d479"}
from {guid: uuid(version="v7")}
{guid: "018ecb4f-abc1-7123-8def-0123456789ab"}
from {guid: uuid(version="nil")}
{guid: "00000000-0000-0000-0000-000000000000"}

random

Last updated: