Created
February 9, 2023 02:48
-
-
Save mdestafadilah/d985c1688ec65f476fd79723e611c640 to your computer and use it in GitHub Desktop.
RANDOM NUMBER IN PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$date = date("Y-m-d H:i:s"); | |
$day_number = date('N', strtotime($date)); | |
echo $day_number; | |
echo "\n";echo "===="; echo "\n"; | |
echo ($day_number % 2 == 0) ? '1' : '2'; | |
echo "\n"; | |
function generateRandomBot($min = 1, $max = 2) | |
{ | |
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 | |
} | |
echo "\n"; echo "====="; echo "\n"; | |
echo generateRandomBot(1,4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment