---
title: "getRandomUUID"
description: "生成符合 RFC 4122 标准的随机 UUID v4 字符串，优先使用 crypto.randomUUID。"
seo_title: "getRandomUUID"
seo_description: "Generate a random RFC 4122 version 4 UUID string, using the platform crypto API for collision-resistant unique identifiers."
canonical_url: "https://core.mhaibaraai.cn/docs/helpers/uuid"
---
# getRandomUUID

> 生成符合 RFC 4122 标准的随机 UUID v4 字符串，优先使用 crypto.randomUUID。

## 用法

`getRandomUUID` 函数用于生成符合 UUID v4 格式的随机字符串。

```ts
import { getRandomUUID } from '@movk/core'

const id1 = getRandomUUID()
console.log(id1) // 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

const id2 = getRandomUUID()
console.log(id2) // 'f47ac10b-58cc-4372-a567-0e02b2c3d480'

// 用于生成唯一标识符
const componentId = `component-${getRandomUUID()}`
```

## API

### `getRandomUUID()`

生成随机 UUID 字符串。

### 返回值

**返回值** (`string`): 符合 UUID v4 格式的随机字符串。

## Changelog

See commit history for [src/helpers/getRandomUUID.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/helpers/getRandomUUID.ts).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
