先导入命名空间using System.Text;//用于使用StringBuilder 方法
protected static string GetNumPwd(int num)//生成数字随机数
{
string a = "0123456789";
StringBuilder sb = new StringBuilder();
for(int i = 0; i < num; i++)
{
sb.Append(a[new Random(Guid.NewGuid().GetHashCode()).Next(0, a.Length -1)]);
}
return sb.ToString();
}
protected static string GetAbcPwd(int num)//生成字母随机数
{
string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < num; i++)
{
sb.Append(a[new Random(Guid.NewGuid().GetHashCode()).Next(0, a.Length - 1)]);
}
return sb.ToString();
}
protected static string GetMixPwd(int num)//生成混合随机数
{
string a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < num; i++)
{
sb.Append(a[new Random(Guid.NewGuid().GetHashCode()).Next(0, a.Length - 1)]);
}
return sb.ToString();
}
public string GetValidCode() //生成混合随机数
{
string n = string.Empty;
n = Guid.NewGuid().ToString().Substring(0,6);
Response.Write(n);
return n;
}