随机值 - 随机数字 - 随机字母
// 随机值 (返回一个 0到dwValue-1 的随机数值)
DWORD GetRandRemainder(DWORD dwValue)
{
DWORD dwEax;
Sleep(1);
__asm
{
_emit 0x0f
_emit 0x31
mov dwEax,eax
}
return dwEax % dwValue;
}
// 随机数字和字母(minLen 最小长度, maxLen 最大长度)
CString GetRandomStr(int minLen, int maxLen)
{
if (maxLen >= 100)
{
return "ERROR";
}
CString strRet;
int strLen = minLen + this->GetRandRemainder(maxLen-minLen+1);
char chTmp[100] = {0};
int iFlag = 0;
for (int i=0; i<=strLen; i++)
{
iFlag = this->GetRandRemainder(2);// 随机决定该位 字母或数字
if (iFlag==0)
{
chTmp[i] = (char)(48+this->GetRandRemainder(10));// 将随机数值ASCII转化为数字
}
else
{
chTmp[i] = (char)(97+this->GetRandRemainder(26));// 将随机数值ASCII转化为小写字母
}
}
chTmp[strLen+1] = '\0';
strRet.Format("%s", chTmp);
return strRet.GetBuffer(NULL);
}
浙公网安备 33010602011771号