Menu Home

random_bytes

osbo.com | PHP | Functions | random_bytes

Generates cryptographically secure pseudo-random bytes

Syntax

random_bytes ( int $length ) : string

Parameters

length

The length of the random string that should be returned in bytes.

Return

Returns a string containing the requested number of cryptographically secure random bytes.

Examples

<?

$length = 4;

$return = random_bytes($length);

$hexadecimal = bin2hex($return);

echo $hexadecimal;

?>
a425b826

PHP