gmp_random_range


gmp apg

GENERATE a random GMP number within a range.





$min and $max can both be negative or positive, since $min < $max, always.



<?php

GMP gmp_random_range 
( GMP|int|string $min, 
                                          
GMP|int|string $max )

where,

$min = The lower bound for the random number

$max 
= The upper bound for the random number

?>
 

$min


The lower bound for the random number.



$max


The upper bound for the random number.



  1 EXERCISE   

<?php

// For each run of this exercise 
// a new result will be issued

$min01 = PHP_INT_MIN;

$max01 = PHP_INT_MAX;

$rnd01 = gmp_random_range($min01, $max01);

echo 
'gmp_random_range( ' . $min01 . ', ' . $max01 . ' ) =<br><br>= ' . 
                                                           
gmp_strval($rnd01);

?> 

  2 EXERCISE   

<?php

// A warning or a Fatal error is issued
// by this exercise depending the PHP version

echo 'PHP = ' .PHP_VERSION . '<br><br>';

$min02 = 999;

$max02 = 0;

$rnd02 = gmp_random_range($min02, $max02);

echo 
'gmp_random_range( ' . $min02 . ', ' . $max02 . ' ) =<br><br>= ' . 
                                                           
gmp_strval($rnd02);

?>