/// <summary> /// Generates a random DateTime in the range ['minYear', 'maxYear']. This /// method generate dates without time(or time set to 00:00:00) /// </summary> /// <param name="min">(optional) minimum range value</param> /// <param name="max">max range value</param> /// <returns>a random DateTime value.</returns> public static DateTime NextDate(DateTime min, DateTime max) { var diff = RandomDouble.NextDouble(max.Subtract(min).TotalSeconds); var date = min.AddSeconds(diff); return(new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, 0, min.Kind)); }
public void TestNextDouble() { double value = RandomDouble.NextDouble(5); Assert.True(value < 5); Assert.True(value == DoubleConverter.ToDouble(value)); value = RandomDouble.NextDouble(2, 5); Assert.True(value < 5 && value > 2); Assert.True(value == DoubleConverter.ToDouble(value)); }
/// <summary> /// Generates a random DateTime and time in the range ['minYear', 'maxYear']. /// This method generate dates without time(or time set to 00:00:00) /// </summary> /// <param name="min">minimum range value</param> /// <param name="max">max range value</param> /// <returns>a random DateTime value.</returns> public static DateTime NextDateTime(DateTime min, DateTime max) { var diff = RandomDouble.NextDouble(max.Subtract(min).TotalSeconds); return(min.AddSeconds(diff)); }