Beispiel #1
0
        public static byte[] RandomByteString(IRandomGenExtended rand, int length)
        {
            if (rand == null)
            {
                throw new ArgumentNullException(nameof(rand));
            }
            var bytes = new byte[length];

            rand.GetBytes(bytes, 0, bytes.Length);
            return(bytes);
        }
Beispiel #2
0
 private static void AppendRandomDecimalsLong(
     IRandomGenExtended r,
     StringBuilder sb,
     long count)
 {
     if (sb == null)
     {
         throw new ArgumentNullException(nameof(sb));
     }
     if (r == null)
     {
         throw new ArgumentNullException(nameof(r));
     }
     if (count > 0)
     {
         var buflen = (int)Math.Min(0x10000, Math.Max(count + 8, 64));
         var buffer = new byte[buflen];
         while (count > 0)
         {
             r.GetBytes(buffer, 0, buflen);
             var i = 0;
             while (i < buflen && count > 0)
             {
                 int x = ((int)buffer[i]) & 31;
                 if (x < 30)
                 {
                     sb.Append(charTable[x]);
                     --count;
                     ++i;
                 }
                 else if (count >= 40 && i + 1 < buflen)
                 {
                     int y = (((int)buffer[i + 1]) & 0xff) %
                             valueSpecialDecimals2.Length;
                     sb.Append(valueSpecialDecimals2[y]);
                     count -= 40;
                     i     += 2;
                 }
                 else if (count >= 10 && i + 1 < buflen)
                 {
                     int y = (((int)buffer[i + 1]) & 0xff) %
                             valueSpecialDecimals.Length;
                     sb.Append(valueSpecialDecimals[y]);
                     count -= 10;
                     i     += 2;
                 }
                 else
                 {
                     ++i;
                 }
             }
         }
     }
 }
Beispiel #3
0
        public static byte[] RandomByteString(IRandomGenExtended rand)
        {
            if (rand == null)
            {
                throw new ArgumentNullException(nameof(rand));
            }
            int x     = rand.GetInt32(MaxExclusiveStringLength);
            var bytes = new byte[x];

            rand.GetBytes(bytes, 0, bytes.Length);
            return(bytes);
        }