#include <QRandomGenerator>
/**
*
* @brief: 获得随机字符串
* @param nLen: 字符串个数
* @return: 字符串
*/
QString getRandomString(int nLen);
QString QSoundPlayer::getRandomString(int nLen)
{
QRandomGenerator::global()->generate();
const char ch[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int size = sizeof(ch);
char* str = new char[nLen + 1];
int num = 0;
for (int nIndex = 0; nIndex < nLen; ++nIndex)
{
num = rand() % (size - 1);
str[nIndex] = ch[num];
}
str[nLen] = '\0';
QString res(str);
return res;
}
[qt]获得随机你字符串
最新推荐文章于 2023-07-20 23:45:09 发布