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

# 生成 UUID

使用 `crypto.randomUUID()` 来生成一个 UUID v4。该 API 可在 Bun、Node.js 和浏览器中使用，无需任何依赖。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
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={"theme":{"light":"github-light","dark":"dracula"}}
Bun.randomUUIDv7();
// => "0196a000-bb12-7000-905e-8039f5d5b206"
```

***

更多有用的工具请见 [文档 > API > 实用工具](/runtime/utils)。
