Skip to main content

bn.getRandomValues

getRandomValues(options): GetRandomValuesResult

description Obtaining cryptographically secure random numbers. This api is not excatly the same as the web crypto api. But you can acheive the same goal. Check the example below.

remark supported jssdk > 4.27.0

example


const typedArray = new Uint8Array(10)
const buffer = await bn.getRandomValues({ length: typedArray.buffer.byteLength })
const resArr = new typedArray.constructor(buffer)
for (let i = 0; i < typedArray.length; i++) {
typedArray[i] = resArr[i]
}

Parameters

NameType
optionsGetRandomValuesOptions

Returns

GetRandomValuesResult

Interface: GetRandomValuesOptions

NameTypeDescription
lengthnumber

Interface: GetRandomValuesResult

NameTypeDescription
randomValuesArrayBuffer