random_bytes
Description
The random_bytes of Random for PHP gets cryptographically secure random bytes.
Syntax
random_bytes(
int $length
): stringParameters
length
The length of the random string that should be returned in bytes; must be 1 or greater.
Return
Returns a string containing the requested number of cryptographically secure random bytes.
Examples
1 · length
<? $length = 10; $return = random_bytes($length); var_dump($return);
string(10) "|!;c��S|�"
2 · hexadecimal
<? $length = 10; $return = random_bytes($length); $hexadecimal = bin2hex($return); var_dump($return, $hexadecimal);
string(10) "����b{����"
string(20) "96ff89a5627b80a2c2c5"