示例#1
0
        /// <summary>生成随机的银行卡卡号
        /// </summary>
        /// <param name="prefix"> </param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetFixNumberString(int prefix = 0, int length = 16)
        {
            if (length < 1)
            {
                throw new ArgumentException("卡号长度不能小于1");
            }
            var prefixLength = UtilityMath.GetLength(prefix);
            var sb           = new StringBuilder(length);

            if (prefix > 0)
            {
                if (prefixLength > length)
                {
                    sb.Append(prefix.ToString().Substring(0, length));
                }
                else
                {
                    sb.Append(prefix);
                }
            }
            for (int i = 0; i < length - prefixLength; i++)
            {
                sb.Append(Random.Next(0, 9));
            }
            return(sb.ToString());
        }