random_int


crypto apg

GENERATES cryptographic random integers that are suitable for use where unbiased results are critical, such as when shuffling a deck of cards for a poker game.



RANDOM NUMBERS

are numbers that occur in a sequence such that two conditions are met:

1 . the values are uniformly distributed over a defined interval or set.
2 . it is impossible to predict future values based on past or present ones.

Random numbers are important in statistical analysis and probability theory.

This function generates cryptographically secure values, and it should be used for these purposes.

 random_int  should be used instead of  rand  because it is much faster.

You can see more:

   CryptGenRandom function on Windows  !

   CNG-API on Windows  !

   GETRANDOM(2) on LINUX  !



<?php

int random_int 
int $min int $max )


where,


$min the minimum integer value
           of the numeric interval
           
must be PHP_INT_MIN or higher )

$max the maximun integer value
            of the numeric interval
            
must be less than or equal to PHP_INT_MAX )
                                
?>

$min


The minimum integer value of the numeric interval.

Depending on the system:

PHP_INT_MIN = -9223372036854775808



$max


The maximum integer value of the numeric interval.

Depending on the system:

PHP_INT_MAX = 9223372036854775807



  1 EXERCISE   

<?php

// Run this code several times

// Always use the current version of PHP

$min PHP_INT_MIN;

$max PHP_INT_MAX;

$rndint random_int $min $max );

echo 
'Random value generated at this moment:<br><br>' $rndint '<br>';
                                
?>