Answers for "generate random string in c++"

C++
0

generate random string in c++

#include <random>
#include <string>

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         
}
Posted by: Guest on September-01-2021

Code answers related to "generate random string in c++"

Browse Popular Code Answers by Language