> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 生成 UUID

使用 `crypto.randomUUID()` 生成 UUID v4。它在 Bun、Node.js 和浏览器中均可使用，无需依赖。

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

***

Bun 还提供 `Bun.randomUUIDv7()`，用于生成 [UUID v7](https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-01.html)。

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

***

参见 [工具](/runtime/utils)。
