コード例 #1
0
        public string GetRandomNumericString(int length)
        {
            var ranString = new StringBuilder(length);

            string strRandomNumber = string.Empty;

            for (int i = 0; i < length; ++i)
            {
                int charIndex = RandomNumberHelper.Between(1, 9999);
                if (i > 1 && strRandomNumber.Length > length)
                {
                    break;
                }
                strRandomNumber = strRandomNumber + charIndex;
            }

            ranString.Append(strRandomNumber.Substring(0, length));

            return(ranString.ToString());
        }
コード例 #2
0
        public string GetRandomString(int length)
        {
            var ranString = new StringBuilder(length);

            for (int i = 0; i < length; ++i)
            {
                int charIndex;
                // allow only digits and letters
                do
                {
                    charIndex = RandomNumberHelper.Between(48, 123);
                } while (!((charIndex >= 48 && charIndex <= 57) ||
                           (charIndex >= 65 && charIndex <= 90) ||
                           (charIndex >= 97 && charIndex <= 122))
                         );

                // add the random char to the ranString being built
                ranString.Append(Convert.ToChar(charIndex));
            }
            return(ranString.ToString());
        }
コード例 #3
0
        public string GetRandomUpperCaseNumericString(int length)
        {
            var ranString = new StringBuilder(length);

            for (int i = 0; i < length; ++i)
            {
                int charIndex;
                // allow only digits and upper case letters
                // also dont allow 0,1,I and O
                do
                {
                    charIndex = RandomNumberHelper.Between(50, 90);
                } while (!((charIndex >= 50 && charIndex <= 57) ||
                           (charIndex >= 65 && charIndex <= 72) ||
                           (charIndex >= 74 && charIndex <= 78) ||
                           (charIndex >= 80 && charIndex <= 90)));


                // add the random char to the ranString being built
                ranString.Append(Convert.ToChar(charIndex));
            }
            return(ranString.ToString());
        }
コード例 #4
0
    public static string GetRandomString(int length, bool isNumeric)
    {
        var ranString = new System.Text.StringBuilder(length);
        int charIndex;

        if (!isNumeric)
        {
            for (int i = 1; i <= length; i++)
            {
                // allow only digits and letters
                do
                {
                    charIndex = RandomNumberHelper.Between(48, 123);
                } while (!((charIndex >= 48 && charIndex <= 57) ||
                           (charIndex >= 65 && charIndex <= 90) || (charIndex >= 97 && charIndex <= 122)));

                // add the random char to the ranString being built
                ranString.Append(Convert.ToChar(charIndex));
            }
        }
        else
        {
            string strRandomNumber = string.Empty;
            for (int i = 1; i <= length; i++)
            {
                charIndex = RandomNumberHelper.Between(1, 9999);
                if (i > 1 && strRandomNumber.Length > length)
                {
                    break;
                }
                strRandomNumber = strRandomNumber + charIndex.ToString();
            }
            ranString.Append(strRandomNumber.Substring(0, length));
        }
        return(ranString.ToString());
    }
コード例 #5
0
 private string GenerateUniquePassword()
 {
     return(RandomNumberHelper.Between(10000, 99999).ToString());
 }
コード例 #6
0
 private static int GetRandomNumber(int min, int max)
 {
     return(RandomNumberHelper.Between(min, max));
 }