Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <random>
#include <functional>
inline const std::string generate_ascii_random_string(std::string::size_type n)
{
static std::default_random_engine generator;
static std::uniform_int_distribution<short> distribution(0x20, 0x7A); //ascii range from space to z
static auto rnd = std::bind(distribution, generator);
std::string s;
s.resize(n);
for (auto& ch : s)
ch = static_cast<char>(rnd());
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment