生成随机字符串
parent
2a5156f329
commit
df7c788ec1
|
@ -1,6 +1,7 @@
|
|||
#include "CommonFunctions.h"
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
bool RemoveDir(QString fullpath)
|
||||
{
|
||||
|
@ -33,3 +34,16 @@ QString MODULEBASEAPI doubleToString(double v, int acc)
|
|||
QString vs = QString::asprintf(ba.data(), v);
|
||||
return vs;
|
||||
}
|
||||
|
||||
|
||||
QString MODULEBASEAPI generateRandomString(int length) {
|
||||
const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
|
||||
const int randomStringLength = possibleCharacters.length();
|
||||
|
||||
QString randomString;
|
||||
for(int i = 0; i < length; ++i) {
|
||||
int index = QRandomGenerator::global()->bounded(randomStringLength);
|
||||
randomString.append(possibleCharacters.at(index));
|
||||
}
|
||||
return randomString;
|
||||
}
|
|
@ -10,6 +10,8 @@ extern "C"
|
|||
bool MODULEBASEAPI RemoveDir(QString fullpath);
|
||||
//将浮点数转化为字符串,acc-小数点后位数
|
||||
QString MODULEBASEAPI doubleToString(double v, int acc);
|
||||
// 生成随机字符串
|
||||
QString MODULEBASEAPI generateRandomString(int length);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue