示例#1
0
 // TODO: Put strings into the resources.
 //
 public static long NextInt64(long minInclusive, long maxExclusive)
 {
     minInclusive.Arg(nameof(minInclusive)).EnsureNotEqualTo(long.MinValue);
     if (maxExclusive <= minInclusive)
     {
         throw
             new ArgumentOutOfRangeException(
                 paramName: nameof(maxExclusive),
                 message: $"Значение аргумента должно быть больше значения аргумента '{nameof(minInclusive)}'.{Environment.NewLine}\tЗначение:{Environment.NewLine}{maxExclusive.FmtStr().Decimal().IndentLines2()}{Environment.NewLine}\tЗначение аргумента '{nameof(minInclusive)}':{Environment.NewLine}{minInclusive.FmtStr().Decimal().IndentLines2()}");
     }
     //
     if (minInclusive < 0L && maxExclusive > 0)
     {
         var randomInt64 = NextInt64(0, long.MaxValue);
         if (randomInt64 % 2L == 0L)
         {
             return
                 (randomInt64 < maxExclusive
                                         ? randomInt64
                                         : randomInt64 % maxExclusive);
         }
         else
         {
             return
                 (randomInt64 <= -minInclusive
                                         ? -randomInt64
                                         : -(randomInt64 % -minInclusive) - 1L);
         }
     }
     else
     {
         var rangeSize = maxExclusive - minInclusive;
         if (rangeSize == 1)
         {
             return(minInclusive);
         }
         else if (rangeSize <= int.MaxValue)
         {
             var randomInt32 =
                 Next(
                     minInclusive: 0,
                     maxExclusive: (int)rangeSize);
             return(minInclusive + randomInt32);
         }
         else
         {
             var randomInt64Bytes = new byte[8];
             NextBytesLeft(randomInt64Bytes, 8);
             var randomInt64 = BitConverter.ToInt64(randomInt64Bytes, 0);
             if (randomInt64 < 0L)
             {
                 randomInt64 ^= -1L;
             }
             randomInt64 = randomInt64 % rangeSize;
             return(minInclusive + randomInt64);
         }
     }
 }
示例#2
0
 public TriggerSignalState(long signalCounter, DateTimeOffset lastSignalTimestamp)
 {
     signalCounter.Arg(nameof(signalCounter)).EnsureNotLessThanZero();
     if (signalCounter == 0)
     {
         if (lastSignalTimestamp != default)
         {
             throw new ArgumentOutOfRangeException(paramName: nameof(lastSignalTimestamp));
         }
     }
     else if (lastSignalTimestamp == default)
     {
         throw new ArgumentOutOfRangeException(paramName: nameof(lastSignalTimestamp));
     }
     //
     SignalCounter       = signalCounter;
     LastSignalTimestamp = lastSignalTimestamp;
 }