public static string GetRandomString( int length )
{
Random rd = new Random();
byte[] str = new byte[ length ];
int i;
for( i=0;i<length;i++ )
{
int a = 0;
//while 后的条件用来限定密码的字符集,本例中是限定为大小写字母
while( !((a>=48 && a<=57) ¦ ¦ (a>=65 && a<=90) ¦ ¦ (a>=97 && a<=122)) )
{
a = rd.Next(48,125);
}
str[i] = (byte)a;
}
return new string(UnicodeEncoding.ASCII.GetChars(str));
}
{
Random rd = new Random();
byte[] str = new byte[ length ];
int i;
for( i=0;i<length;i++ )
{
int a = 0;
//while 后的条件用来限定密码的字符集,本例中是限定为大小写字母
while( !((a>=48 && a<=57) ¦ ¦ (a>=65 && a<=90) ¦ ¦ (a>=97 && a<=122)) )
{
a = rd.Next(48,125);
}
str[i] = (byte)a;
}
return new string(UnicodeEncoding.ASCII.GetChars(str));
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货