Wednesday, February 18, 2009

Get a Random Date


static DateTime GetRandomDate(Random rand,
DateTime minDate, DateTime maxDate)
{
TimeSpan ts = maxDate - minDate;
int totalDays = (int)ts.TotalDays;
int randomDays = rand.Next(0, totalDays);
return minDate.AddDays(randomDays);
}

No comments: