用随机字符串和随机数字字符串,很好用,我贴个代码
///
/// 获得数字形式的随机字符串
///
///
数字形式的随机字符串
public static string GetNumberRandom()
{
int intNum;
long lngNum;
string strNum = System.DateTime.Now.ToString();
strNum = strNum.Replace( ": ", " ");
strNum = strNum.Replace( "- ", " ");
strNum = strNum.Replace( " ", " ");
lngNum = long.Parse(strNum);
System.Random objDom = new Random();
intNum = objDom.Next(1000000,9999999);
objDom = null;
lngNum += intNum;
return lngNum.ToString();
}
///
/// 生成标准8位包含特殊字符的随机字符串
///
///
包含特殊字符的随机字符串
public static string GetRandomStringALL()
{
return BuildRndCodeAll(defaultLength);
}
///
/// 生成包含特殊字符的随机字符串,可选择字符数量
///
///
随机字符串长度
///
包含特殊字符的随机字符串
public static string GetRandomStringALL(int Length)
{
return BuildRndCodeAll(Length);
}
///
/// 生成标准8位小写随机字符串,不包含特殊字符
///
///
标准随机字符串
public static string GetRandomStringOnly()
{
return BuildRndCodeOnly(sCharLow + sNumber,defaultLength);
}
///
/// 生成标准8位随机字符串,可选择大小写
///
///
是否包含大小写字母
///
随机字符串
public static string GetRandomStringOnly(bool IsUpper)
{
string strTmp = sCharLow;
if(IsUpper) strTmp += sCharUpp;
return BuildRndCodeOnly(strTmp,defaultLength);
}
///
/// 生成不包含特殊字符的小写随机字符串,可选择字符数量
///
///
随机字符串长度
///
随机字符串
public static string GetRandomStringOnly(int Length)
{
return BuildRndCodeOnly(sCharLow + sNumber,Length);
}
///
/// 生成不包含特殊字符的随机字符串,可选择字符数量和包含大小写
///
///
是否包含大小写字母
///
字符串数量
///
public static string GetRandomStringOnly(bool IsUpper,bool IsUseNumber)
{
string strTmp = sCharLow;
if (IsUpper) strTmp += sCharUpp;
if (IsUseNumber) strTmp += sNumber;
return BuildRndCodeOnly(strTmp,defaultLength);
}
///
/// 生成不包含特殊字符的随机字符串,可选择长度,包含大小写字母和字符数量
///
///
字符数量
///
是否包含大小写字母
///
字符串数来那个
///
随机字符串
public static string GetRandomStringOnly(int Length,bool IsUpper,bool IsUserNumber)
{
string strTmp = sCharLow;
if (IsUpper) strTmp += sCharUpp;
if (IsUserNumber) strTmp += sNumber;
return BuildRndCodeOnly(strTmp,Length);
}