In an attempt to build a flash-based contest game that ties into PHP/MySQL for tracking behind the scenes, I aim to eventually end up with a set date range (ie., between YYYY-MM-DD and YYYY-MM-DD) and pick a random datetime (or two, or three) within the given range, and designate those as winning times. I’m not really sure the best way to go about this, any ideas?
I’m rather new with time + rand() and not sure the best way to go about this. Any advice or helpful snippets that seem to make sense for this application would be grand 😀
This gives you three timestamps within the given range. Timestamps are merely seconds since 1970, so they’re simple sequential numbers. Just pick a random number within the start-end range using
mt_rand. Convert timestamps back to human readable dates using, for example,date('Y-m-d', $winningTimes[0]).To make sure you get unique days, do something like this: