Updated on 2026-10-12 GMT+08:00

Generating a Random Number

Function

This API is used to generate an 8-bit to 8,192-bit random number.

Calling Method

For details, see Calling APIs.

URI

POST /v1.0/{project_id}/kms/gen-random

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID. For details, see Obtaining a Project ID.

Constraints

N/A

Range

The value returned by the IAM API is used, which contains 32 characters.

Default Value

N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token. It can be obtained by calling the IAM API. The value of X-Subject-Token in the response header is the user token.

Constraints

N/A

Range

Obtain the value by calling the IAM API for obtaining the user token.

Default Value

N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

random_data_length

Yes

String

Definition

Bit length of a random number

Constraints

The value must be a multiple of 8.

Range

8 to 8192

Default Value

N/A

sequence

No

String

Definition

A 36-byte serial number of a request message, for example, 919c82d4-8046-4722-9094-35c3c6524cff.

Constraints

N/A

Range

N/A

Default Value

N/A

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

random_data

String

Definition

Random number in hexadecimal format. The length is the value of random_data_length.

Range

N/A

Example Requests

Generate a 512-bit random number.

{
  "random_data_length" : "512"
}

Example Responses

Status code: 200

{
  "random_data" : "b2eab85c95282ceaea6896b5ef4e88e2b614e358ef1785119b47d90a020df50a0e189c07d855dd7360d05e0dfcdc1920bf911ad656ddd73c1a3ff0e6c10290bd"
}

Status Codes

Status Code

Description

200

Request succeeded.

Error Codes

See Error Codes.