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)