我实现了下面的 RandomDate,但我总是让值接近“从”日期,我可能在这里错过了一些东西....
public static DateTime GetRandomDate(DateTime from, DateTime to)
{
var range = new TimeSpan(to.Ticks - from.Ticks);
var rnd = new Random();
var randTimeSpan = new TimeSpan((long)(range.TotalSeconds - rnd.Next(0, (int)range.TotalSeconds)));
return from + randTimeSpan;
}