我正在寻找在C++中生成随机字符串的方法。这是我的代码:
string randomStrGen(int length) {
static string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
string result;
result.resize(length);
srand(time(NULL));
for (int i = 0; i < length; i++)
result[i] = charset[rand() % charset.length()];
return result;
}
但是 seed(time(NULL))
不够随机。在C++中有没有其他更好的方法来生成随机字符串?