> For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt.

# getRandomValues

获取安全随机数。

## 扫码预览

![扫码预览 getRandomValues](https://api.qrserver.com/v1/create-qr-code/?size=200x200\&data=doubao%3A%2F%2Fdoubao_apps%3Fapp_id%3Ddb_1McM5Ni%26path%3D%252Fpages%252Fapi%252Fdevice%252Fget-random-values%252Findex)

## 支持版本

前端库版本不低于 `0.0.25`。

## 支持平台

<table>
<thead>
<tr><th>平台</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>Android</td><td>支持</td></tr>
<tr><td>iOS</td><td>支持</td></tr>
<tr><td>PC</td><td>支持</td></tr>
<tr><td>HarmonyOS</td><td>支持</td></tr>
</tbody>
</table>

## 支持场景

<table>
<thead>
<tr><th>场景</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>页面</td><td>支持</td></tr>
<tr><td>卡片</td><td>不支持</td></tr>
</tbody>
</table>

## 使用说明

- 生成的字节数越大耗时越长，建议按实际需要申请长度

## 调用方式

### 异步 API

```typescript
getRandomValues(params: GetRandomValuesParams): Promise<GetRandomValuesResult>
```

## 入参

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必填</th><th>默认值</th><th>约束</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>length</code></td><td><code>number</code></td><td>是</td><td>-</td><td>取值范围 0 到 1048576 的整数，超出范围会抛出 RangeError</td><td>需要生成的字节数。</td></tr>
</tbody>
</table>

## 调用示例

```typescript
import { getRandomValues } from '@doubao-dev/framework/api';

const { randomValues } = await getRandomValues({ length: 16 });
const bytes = new Uint8Array(randomValues);

console.log(bytes);
```

## 成功返回

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必返</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>randomValues</code></td><td><code>ArrayBuffer</code></td><td>是</td><td>生成的随机字节。</td></tr>
</tbody>
</table>

### 返回示例

```json
{
  "randomValues": {}
}
```
