Search code examples
phpsrand

random number generate in 5 minutes


How can I generate a random number in every 5 minutes? When I searched for it, I found Need to generate random number after time interval. Using that, I coded like,

    <?
    $seed = floor(time()/(60*60*12));
    srand($seed);
    $item = rand(0,9);
    echo $item;
    ?>

But the value of $item is not changing in 5 minute. How can I edit this code?


Solution

  • The example you pulled from the other SO question generates a new random number every TWELVE HOURS, as indicated by the "12" in your code.

    Since you want a new random number every FIVE MINUTES, the code is as follows:

    <?
    $seed = floor(time()/(60*5));
    srand($seed);
    $item = rand(0,9);
    echo $item;
    ?>