HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

random_bytes

Description

The random_bytes of Random for PHP get cryptographically secure random bytes.

Syntax

random_bytes(
    int $length
): string

Parameters

length

The length of the random string that should be returned in bytes; must be 1 or greater.

Return

A string containing the requested number of cryptographically secure random bytes.

Examples

1 · return

<?

$length = 10;

$return = random_bytes($length);

var_dump($return);
string(10) "k� e�۶�8"

2 · hexadecimal

<?

$length = 10;

$return = random_bytes($length);

$hexadecimal = bin2hex($return);

var_dump($hexadecimal);
string(20) "e6d472cbbc49f55fa85b"