直接上代码:

#region 生成N位随机数
/// <summary>
/// 生成N位随机数
/// </summary>
/// <param name="N">N位随机数</param>
/// <returns>生成的N位随机数</returns>
public static string RandCode(int N)
{
char[] arrChar = new char[] { '', '', '', '', '', '', '', '', '', '' };
StringBuilder num = new StringBuilder();
Random rnd = new Random(Guid.NewGuid().GetHashCode());
for (int i = ; i < N; i++)
{
num.Append(arrChar[rnd.Next(, arrChar.Length)].ToString());
}
return num.ToString();
}
#endregion
05-02 21:25