/// <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;
}
/// 此函数将产生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;
}
本文介绍了一种使用C#生成12到20位随机用户名的方法,该方法通过随机选择数字和小写字母来创建唯一用户名。
328

被折叠的 条评论
为什么被折叠?



