PHP CSPRNG
CSPRNG (Cryptographically Secure Pseudo-Random Number Generator, pseudo-random number generator).
PHP 7 provides a simple mechanism by introducing several CSPRNG function to generate random numbers on strong cryptography.
random_bytes () - Survival protected encryption pseudo random string.
random_int () - Survival encryption protected pseudo-random integer.
random_bytes ()
Syntax
string random_bytes ( int $length )
parameter
length - the number of bytes of random string returned.
return value
Returns a string, returns the number of bytes to accept the result of an int on behalf of the Senate.
Examples
Examples
$ bytes = random_bytes (5);
print (bin2hex ($ bytes)) ;
?>
The above program execution output is:
6f36d48a29
random_int ()
Syntax
int random_int ( int $min , int $max )
parameter
min - the minimum return must be greater than or equal PHP_INT_MIN.
max - the maximum return, must be less than or equal PHP_INT_MAX.
return value
Returns a specified number in the range of type int.
Examples
Examples
print (random_int (100, 999) );
print (PHP_EOL);
print (random_int (- 1000, 0 ));
?>
The above program execution output is:
723 -64