samedi 1 juin 2019

Generate Array Randomly only Once a Day

I want to generate random array but once a day and should not be repeated next day or on same date next month. Here is my code...

function Rand1($min, $max, $quantity) {
srand(date("ymd"));
$first = array("A", "B", "C", "D", "E", "F", "G", "H");
shuffle($first);
return array_slice($first, 0, $quantity);
}
$three_array=Rand1(0,8,3);
$three_string=implode(" ",$three_array);
echo $three_string;

It generate D H F for the same day and next day and so on. If I remove this - srand(date("ymd")) then it shows randomly on each page load. But it string should not change for the 24 hours, like this:

If date is 01/06/2019 - D H F

If date is 02/06/2019 - A E B (Any other random order)

If date is 01/07/2019 - B D F (Any other random order)

How can I get this without database or cookie, it should be based on PHP.




Aucun commentaire:

Enregistrer un commentaire