dimanche 29 mars 2015

Same random number each day php

I want to display a quote of the day by finding the id of the post, so I'm using the seeds as the lowest and highest ids, so each day I get a random id, this will display a random post each day. I am using this to generate the same random number each day:



mt_srand(crc32(date('D d F Y')));
echo $random = (mt_rand(1,8288));


This worked perfectly on php version 5.3 or lower however on one of my other servers which is version 5.4.33. It doesn't work and always creates a new one each time. I have changed php versions to test this and it seems that it is the version that affects it. Is there another way to generate a 'consistent random' number each day? I need a number so that I can query the database and show a particular post per day.


I don't want to create another table or add another row to add dates for each post because that'll mean I have to create future dates for each post and there are already too many rows to do that.





Aucun commentaire:

Enregistrer un commentaire