php - how to select random index based on the current time -


given array of length n, how select random index based on current time. wanted generate random integer 0 n based on current time. possible mathematically?

you can seed random number generator derived value time():

mt_srand(time() / 30 / 60); // reseed every 30 minutes  echo mt_rand(0, n); 

without random number generator can use modulo:

echo (time() / 30 / 60) % n; 

note mt_rand() output may include n whereas module version doesn't.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -