php/mysql ordered random dates
===

I found this great function on SO whilst looking for a way to generate random dates between two fixed timestamps:


     function randomDate($start_date, $end_date)
    {
        // Convert to timestamps
        $min = strtotime($start_date);
        $max = strtotime($end_date);
    
        // Generate random number using above bounds
        $val = rand($min, $max);
    
        // Convert back to desired date format
        return date('Y-m-d H:i:s', $val);
    }

[Source and credit][1]

but I am looking for a way for the dates to be generated in order (start date to end date) as I have used it to generate dates to insert into a database.

The problem is my posts are `ORDER BY id DESC` and using the function "as is" being that they are random the dates end up out of sync.

**ie:**

    post id 4 - date = 2010-07-11 14:14:10
    post id 3 - date = 2012-02-22 18:23:21
    post id 2 - date = 2011-03-17 13:52:47
    post id 1 - date = 2011-08-14 15:33:50

and I need them to be in sync with the post id.

Now your thinking why not change the query to `ORDER BY date DESC` instead? ...well that would mess up 99% of code I have already written as there are other columns/rows dependent on it being `ORDER BY id DESC` and so ordering the dates when being inserted into the database is the only solution.

  [1]: http://stackoverflow.com/questions/1972712/generate-random-date-between-two-dates-using-php/10103901#10103901