Skip to content

Instantly share code, notes, and snippets.

@fabiogaluppo
Last active January 26, 2016 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiogaluppo/f91f41c2bcb7023e64c8 to your computer and use it in GitHub Desktop.
Save fabiogaluppo/f91f41c2bcb7023e64c8 to your computer and use it in GitHub Desktop.
#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