This isn't necessarily specific to PHP, but I am trying to figure out a way to pseudo-randomly generate a number based on the month. To clarify a little, I want the number returned to stay the same for the entire month, and then change to another "random" number for the next month. There would also need to be a ceiling on how big the number could be. I can't think of a way to write this, is there anyone able to help?
Pseudo-random month based selection
Collapse
X
-
Hi.
You can use the mt_rand function to generate a random number. You can even specify the lowest and highest limits.
As to using a single random number for the entire month. You will obviously have to store this number somewhere, where it can be read by your code. I would probably use a Database, like MySQL.
You would simply have to have a field for your random number, and a date field for the month it represents. If there is not a field for the current month, you use the function to generate a new number and add it for the current month.
Comment