Пример #1
0
        public static DateTime RandomDate(int minimum, int maximum, bool future = false)
        {
            int year  = DateTime.Today.Year + RandomAge(minimum, maximum) * (future ? 1 : -1);
            int month = RNGRandomHelper.Next(1, 12);
            int day   = RandomDay(year, month);

            return(new DateTime(year, month, day, RNGRandomHelper.Next(0, 23), RNGRandomHelper.Next(0, 59), RNGRandomHelper.Next(0, 59)));
        }
Пример #2
0
        public static int RandomDay(int year, int month)
        {
            if (!IsYear(year))
            {
                throw new ArgumentOutOfRangeException(nameof(year));
            }
            if (!IsMonth(month))
            {
                throw new ArgumentOutOfRangeException(nameof(month));
            }
            DateTime date = new DateTime(year, month, 1);

            return(RNGRandomHelper.Next(1, date.DaysInMonth()));
        }
Пример #3
0
 public static int RandomAge(int minimum, int maximum)
 {
     if (!minimum.InRange(1, byte.MaxValue))
     {
         throw new ArgumentOutOfRangeException(nameof(minimum));
     }
     if (!maximum.InRange(1, byte.MaxValue))
     {
         throw new ArgumentOutOfRangeException(nameof(maximum));
     }
     if (maximum < minimum)
     {
         throw new ArgumentOutOfRangeException(nameof(maximum));
     }
     return(RNGRandomHelper.Next(minimum, maximum));
 }
Пример #4
0
        public static string RandomKey(byte size)
        {
            if (size == 0)
            {
                size = (byte)RandomHelper.Next(1, byte.MaxValue);
            }

            char          start = 'A', end = 'Z';
            StringBuilder sb = new StringBuilder(size);

            sb.Append((char)RNGRandomHelper.Next(start, end));

            for (int i = 0; i < size - 1; i++)
            {
                int range = RNGRandomHelper.Next(0, 2);

                switch (range)
                {
                case 0:
                    start = 'A';
                    end   = 'Z';
                    break;

                case 1:
                    start = 'a';
                    end   = 'z';
                    break;

                default:
                    start = '0';
                    end   = '9';
                    break;
                }

                sb.Append((char)RNGRandomHelper.Next(start, end));
            }

            return(sb.ToString());
        }