//随机汉字
void RandomChinese(QByteArray &arr, int count){
QTime time;time= QTime::currentTime();qsrand(time.msec()+time.second()*1000);int high = 0xd7 - 0xc1;//16-55区汉字int low= 0xfe - 0xa1;char name[3];name[2]='\0';for(int k=0;k<count;k++){int high_zn = qrand()%high + 0xc1;int low_zn = qrand()%low + 0xa1;name[0]=high_zn;name[1]=low_zn;arr.append(name);}arr=QString::fromLocal8Bit(arr).toUtf8();
}
//随机数字
void RandomNumber(QByteArray &arr, int count){
QTime time;time=QTime::currentTime();qsrand(time.msec()+time.second()*1000);for(int i=0;i<count;i++){arr.append(QString::number(rand()%9));}}
//随机英文字母
void RandomLetter(QByteArray &arr, int count){
QTime time;time=QTime::currentTime();qsrand(time.msec()+time.second()*1000);
for(int i=0;i<count;i++){int Letter=qrand()%57+65;while(Letter>=91&&Letter<=96){Letter=qrand()%57+65;}
arr.append(Letter);}}
//随机英文字母和数字
void RandomNumberAndLetter(QByteArray &arr, int count){
int scope= 122-48;QTime time;time=QTime::currentTime();qsrand(time.msec()+time.second()*1000);for(int i=0;i<count;i++){int iresult =rand()%scope+48;while ((iresult>=91&&iresult<=96)||(iresult>=58&&iresult<=64)){iresult =rand()%scope+48;}
arr.append(iresult);}}
QT随机数qsrand();
最新推荐文章于 2024-05-21 09:34:07 发布