【Qt】随机字符串

Qt生成自定义字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
qsrand(QDateTime::currentMSecsSinceEpoch());
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);

QLOG_INFO() << __FUNCTION__ << __LINE__ << res;

m_RandomCode = res;

【Qt】随机字符串
https://hodlyounger.github.io/B_Code/Qt/【Qt】随机字符串/
作者
mingming
发布于
2023年10月27日
许可协议