/*!
* \brief getRandomCode 生成指定长度的随机字符串(数组和字母组合)
* \param codelength 指定字符串长度
* \return 生成的字符串
*/
QString getRandomCode( int codelength)
{
const QString codenum = "0123456789";
const QString codestr = "abcdefghijklmnopqrstuvwxyz";
QString code;
/// 添加随机数种子
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
for(int i=0; i< codelength; i++)
{
int type = qrand()%2 ; /// 0表示数字 1表示字符
if(!type){// 数字
int pos = qrand()%10;
code.append(codenum.at(pos));
}else{// 字母
int pos = qrand()%24;
code.append(codestr.at(pos));
}
}
return code;
}