Random static date generation?
March 6, 2010 11:32 AM Subscribe
I need to create a static random number based solely on the date in PHP...I *think* this is possible, but I'm not sure.
posted by omnipotentq to computers & internet (8 answers total) 1 user marked this as a favorite
I have a small system set up where I need to generate a single random number between two values (15 and 20, for this example) based on the date. So, for example, today, no matter how many times the function is called, it will always return, say, "16" because that's the random number based on today's date. But tomorrow, once the date switches over, it will be, say, "20" no matter how many times the function is called.
I've thought about populating a mysql table with random values to call from the database so they'll be constant based on the date, but don't want to generate a table of dates and numbers for every date from here out to whenever I might stop using the system.
The only way I can think of doing this in just php is to grab the current date and somehow base the formula off of that. I could use the rand() function, but every time I call the page, it will display a different random number between 15 and 20 for that particular day. I want the random number to be constant for each date.