Skip to content

Instantly share code, notes, and snippets.

@mdestafadilah
Created February 9, 2023 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdestafadilah/d985c1688ec65f476fd79723e611c640 to your computer and use it in GitHub Desktop.
Save mdestafadilah/d985c1688ec65f476fd79723e611c640 to your computer and use it in GitHub Desktop.
RANDOM NUMBER IN PHP
<?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