您的位置:首页 > 其它

用ASCII的方法产生随机用户名或密码

2007-06-02 08:55 260 查看
/// <summary>
/// 此函数将产生12~20位的随机用户名
/// </summary>
/// <param name="length">输入12-20之间的数字</param>
/// <returns>此函数将产生12~20位的随机用户名,返回string类型</returns>
public void GetRandomString(int length)
{
Random rd = new Random();
byte[] str = new byte[length];
int i;
for (i = 0; i < length; i++)
{
int a = 0;
while (!((a >= 48 && a <= 57) || (a >= 97 && a <= 122)))
{
a = rd.Next(48, 122);
}
str[i] = (byte)a;
}
string username = new string(UnicodeEncoding.ASCII.GetChars(str));
this.register = username;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: