我正在寻找在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;
}
Run Code Online (Sandbox Code Playgroud)
但这seed(time(NULL))不是随机的.还有其他更好的方法在C++中生成随机字符串吗?