PHP CSPRNG
CSPRNG (Cryptographically Secure Pseudo-Random Number Generator).
PHP 7 provides a simple mechanism to generate cryptographically strong random numbers by introducing several CSPRNG functions.
-
random_bytes() - Generates a random string.
-
random_int() - Generates a random integer.
random_bytes()
Syntax format
string random_bytes ( int $length )
Parameters
-
length - The number of bytes returned by the random string.
Return Value
-
Returns a string, accepting an int parameter representing the number of bytes of the returned result.
Example
Example
The output of the above program is:
6f36d48a29
random_int()
Syntax format
int random_int ( int $min , int $max )
Parameters
-
min - The minimum value to return, which must be greater than or equal to PHP_INT_MIN.
-
max - The maximum value to return, which must be less than or equal to PHP_INT_MAX.
Return Value
-
Returns an int number within a specified range.
Example
Example
The output of the above program is:
723
-64
PHP 7 New Features