mynameiskostya Asked:2022-08-25 21:55:48 +0800 CST2022-08-25 21:55:48 +0800 CST 2022-08-25 21:55:48 +0800 CST Qt C++ 中的随机字符串生成 772 如何使用 Qt C++ 优雅地生成随机文本字符串(可选用 Cyrillic)? qt 1 个回答 Voted Best Answer mynameiskostya 2022-08-25T21:55:48+08:002022-08-25T21:55:48+08:00 #include <QRandomGenerator> #include <QString> QString randomString(int length) { static const QString table {"0123456789" "abcdefghij" "klmnkpqrst" "uvwxyzABCD" "EFGHIJKLMN" "hPQRSTUVWX"}; static const int posLimit = table.size() - 1; QString value; while(value.size() < length) { value += table[ QRandomGenerator::system()->bounded (0, posLimit) ]; } return value; } YWNldG9uZQ==
YWNldG9uZQ==