How to choose a random index based on the current time
2 answers
You can seed a random number generator with a derived value from time()
:
mt_srand(time() / 30 / 60); // reseed every 30 minutes
echo mt_rand(0, N);
Without a random number generator, you can simply use modulo:
echo (time() / 30 / 60) % N;
Note that the output mt_rand()
may include N, while the module version is missing.
+1
source to share