# Generate a UUID (/docs/guides/util/javascript-uuid)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 114 · updated: 2026-07-28 -->
Related: [Upgrade Bun to the latest version](/docs/guides/util/upgrade.md), [Detect when code is executed with Bun](/docs/guides/util/detect-bun.md), [Get the current Bun version](/docs/guides/util/version.md), [Hash a password](/docs/guides/util/hash-a-password.md), [Encode and decode base64 data](/docs/guides/util/base64.md), [Compress and decompress data with gzip](/docs/guides/util/gzip.md)

Use `crypto.randomUUID()` to generate a UUID v4. It works in Bun, Node.js, and browsers, with no dependencies.

```ts
crypto.randomUUID();
// => "123e4567-e89b-42d3-a456-426614174000"
```

***

Bun also provides `Bun.randomUUIDv7()`, which generates a [UUID v7](https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-01.html).

```ts
Bun.randomUUIDv7();
// => "0196a000-bb12-7000-905e-8039f5d5b206"
```

***

See [Utils](/runtime/utils).
