赞
踩
记录一个生成8位字母数字组合随机的字符串:
byte[] r = new byte[8];
Random rand = new Random((int)(DateTime.Now.Ticks%1000000));
//生成8字节原始数据
for (int i = 0; i < 8; i++)
//while循环剔除非字母和数字的随机数
do
{
//数字范围是ASCII码中字母数字和一些符号
ran = rand.Next(48, 122);
r[i] = Convert.ToByte(ran);
} while ((ran >= 58 && ran <= 64) || (ran >= 91 && ran <= 96));
//转换成8位String类型
string randomID = Encoding.ASCII.GetString(r);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。