📜  在 C++ 代码示例中生成随机字符串

📅  最后修改于: 2022-03-11 14:44:48.765000             🧑  作者: Mango

代码示例1
#include 
#include 

std::string random_string()
{
     std::string str("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");

     std::random_device rd;
     std::mt19937 generator(rd());

     std::shuffle(str.begin(), str.end(), generator);

     return str.substr(0, 32);    // assumes 32 < number of characters in str         
}