tencent cloud

Encryption
Last updated: 2024-11-21 18:48:11
Encryption
Last updated: 2024-11-21 18:48:11

getRandomValues

This API is used via wx.getRandomValues(Object object).
Feature Description: Gets cryptographically secure random numbers.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
length
number
-
Yes
Integer, the byte size of the generated random number, with a maximum of 1048576.
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Parameters for object.success callback function: Object res.
Attribute
Type
Description
randomValues
ArrayBuffer
Random number content, with a length equivalent to the passed-in byte size.
Sample Code
wx.getRandomValues({
length: 6 // Generate a random number of 6-byte length,
success: res => {
console.log(wx.arrayBufferToBase64(res.randomValues)) // Print after converting to a base64 string
}
})

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback