# wx.getRandomValues(Object object)
Start from base library version 2.15.0. Please remaining backward compatible.
with Promise style call: Supported
Mini Program plugin: Not supported
Obtaining cryptographically secure random numbers
# parameter
# Object object
attribute | type | Default values | Required | Introductions |
---|---|---|---|---|
length | number | yes | Integer, number of bytes to generate random numbers, maximum 1048576 | |
success | function | no | Interface calls the successful callback function | |
fail | function | no | Interface calls failed callback functions | |
complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) |
# object.success callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
randomValues | ArrayBuffer | Random number content, length is the number of bytes passed in |
# sample code
wx.getRandomValues({
length: 6 // Generation 6 A random number of bytes in length,
success: res => {
console.log(wx.arrayBufferToBase64(res.randomValues)) // Convert to base64 Print after string
}
})