目录

Encryption

has.getRandomValues

has.getRandomValues(Object object)

Obtains the cryptographic secure random number.

Since: 1.0.12

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
length number Yes Integer. The number of bytes in a random number. The maximum value is 1048576.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Return value of success

Parameter Type Description
randomValues ArrayBuffer Random number content. The length is the number of input bytes.

Error code information

Error Code Error Message
102 getRandomValues param error.
12004201

getRandomValues error.

For details, see Crypto Framework Error Codes.

Example:

has.getRandomValues({
  length: 6 // Generate a random number with six bytes.
  success: (res) => {
    const randomValues = has.arrayBufferToBase64(res.randomValues); // Convert the random number to a Base64 string and print it.
    console.info('getRandomValues success', randomValues);
  },
  fail: (err) => {
    console.error('getRandomValues fail', err);
  },
  complete: (res) => {
    console.info('getRandomValues complete', res);
  }
});