コード例 #1
0
        public static TimeSpan NextTimeSpan(this SafeRandom random, TimeSpan timeSpan)
        {
            if (timeSpan <= TimeSpan.Zero)
            {
                ThrowHelper.ArgumentOutOfRangeException_NextTimeSpan_Positive(timeSpan, ExceptionArgument.timeSpan);
            }
            double ticksD = ((double)timeSpan.Ticks) * random.NextDouble();
            long   ticks  = checked ((long)ticksD);

            return(TimeSpan.FromTicks(ticks));
        }
コード例 #2
0
        public static TimeSpan NextTimeSpan(this SafeRandom random, TimeSpan minValue, TimeSpan maxValue)
        {
            if (minValue <= TimeSpan.Zero)
            {
                ThrowHelper.ArgumentOutOfRangeException_NextTimeSpan_Positive(minValue, ExceptionArgument.minValue);
            }
            if (minValue >= maxValue)
            {
                ThrowHelper.ArgumentOutOfRangeException_NextTimeSpan_minValue(minValue);
            }
            var span = maxValue - minValue;

            return(minValue + random.NextTimeSpan(span));
        }