PHP CSPRNG
PHP CSPRNG
CSPRNG (Cryptographically Secure Pseudo-Random Number Generator, pseudo-random number generator).
PHP 7 provides a simple mechanism for generating cryptographically strong random numbers by introducing several CSPRNG functions.
random_bytes()- Cryptographically protected pseudo-random string.
random_int()- Cryptographically protected pseudo-random integer.
random_bytes()
Syntax format
Parameters
#length- The number of bytes returned by the random string.
Return value
Returns a string and accepts an int type input parameter representing the number of bytes of the returned result.
Example
The execution output of the above program is:
random_int()
Syntax format
Parameters
min- The minimum value returned, must be greater than or equal to PHP_INT_MIN.
max- The maximum value returned, must be less than or equal to PHP_INT_MAX .
Return value
Returns an int number within the specified range
Example
The execution output of the above program is:
-64