Skip to main content
版本:v3+

getRandomValues

API_LEVEL 5.0 开始支持,API 兼容性请参考 API_LEVEL。

使用硬件随机数填充传入的 Uint8Array,并返回同一个数组对象。失败时抛出异常。

类型​

function getRandomValues(array: InputArray): Result

参数​

InputArray​

类型说明
Uint8Array待填充硬件随机数的 Uint8Array

Result​

类型说明
Uint8Array填充随机数后的原数组对象

代码示例​

import { getRandomValues } from '@zos/crypto'

const bytes = new Uint8Array(16)
getRandomValues(bytes)
console.log(bytes)