Description

This function generates a random text string.

Examples 


https://hostname.example.com:2087/cpsess###########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Rand&cpanel_jsonapi_func=getranddata&length=20

$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// Generate a 20-character random text string
$random = $cpanel->api2(
    'Rand', 'randdata', 
    array(
        'length' => '20',
    ) 
);

 

my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# Generate a 20-character random text string
my $random = $cpliveapi->api2(
    'Rand', 'randdata',
    { 
        'length' => '20',
    }
);

 

cpapi2 --user=username Rand getranddata length=20

{
  "cpanelresult": {
    "apiversion": 2,
    "func": "getranddata",
    "data": [
      {
        "random": "0d8GW1dESHkXJckZgrTX"
      }
    ],
    "event": {
      "result": 1
    },
    "module": "Rand"
  }
}

   

Parameters

ParameterTypeDescriptionPossible valuesExample
lengthstring

Required

The string's character length.

A positive integer.20

Returns

ReturnTypeDescriptionPossible valuesExample
randomstring

The text string.

A string.0d8GW1dESHkXJckZgrTX
reasonstring

A reason for failure.

This function only returns a reason value if it failed.

A string that describes the error.

This is an error message.
resultBoolean

Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.
1