Random DateTime between range - not unified output
问题 I implemented the below RandomDate, but I always keep getting values closed to "From" date, i probably miss something here.... 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; } 回答1: You could change to: static readonly Random rnd = new Random(); public static DateTime