Is there a way to generate a random number based on a min and max?
For example, if min was 1 and max 20 it should generate any number between 1 and 20, including 1 a
I have bundled the answers here and made it version independent;
function generateRandom($min = 1, $max = 20) {
if (function_exists('random_int')):
return random_int($min, $max); // more secure
elseif (function_exists('mt_rand')):
return mt_rand($min, $max); // faster
endif;
return rand($min, $max); // old
}