make_rand_str()

function make_rand_str(int $length = 32, bool $uppercase = false): string

Description

Generates a cryptographically secure random string of alphanumeric characters. This is useful for generating tokens, passwords, API keys, and other identifiers.

Parameters

Parameter Type Description Default
$length int The length of the random string to generate. 32
$uppercase bool Whether to include uppercase characters in the generated string. false

Return Value

Type Description
string The randomly generated alphanumeric string.

Example Usage

PHP
$token = make_rand_str();
echo $token; // e.g., "a3f8k2d9..."

$key = make_rand_str(16, true);
echo $key; // e.g., "K7dF2pX9..." (mixed case)