Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created April 18, 2017 09:36
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 deque-blog/1f83418db6c0e287e498074a46729ca2 to your computer and use it in GitHub Desktop.
Save deque-blog/1f83418db6c0e287e498074a46729ca2 to your computer and use it in GitHub Desktop.
inline auto cpp_identifier_gen(int max_size)
{
using namespace tiny_rand;
static const std::string HEAD_CHARS = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const auto head_char_gen = choice_gen(HEAD_CHARS);
static const auto rest_gen = string_gen(max_size - 1, choice_gen(HEAD_CHARS + "1234567890"));
return [=](std::mt19937& bit_gen) -> std::string
{
return std::string {1, head_char_gen(bit_gen)} + rest_gen(bit_gen);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment