Skip to content

Instantly share code, notes, and snippets.

@jingzhehu
Created July 14, 2018 16:51
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 jingzhehu/d293ee67c418cc14fd07164d6bde2123 to your computer and use it in GitHub Desktop.
Save jingzhehu/d293ee67c418cc14fd07164d6bde2123 to your computer and use it in GitHub Desktop.
Generate random id
#include <random>
decltype(auto) generate_id(){
std::string id("ID"); // Holds the ID, starting with the characters "ID" followed
std::uniform_int_distribution<int> dist(0, 10000); // by a random integer in the range [0-10000].
std::random_device rd;
std::mt19937 engine(rd());
id += std::to_string(dist(engine));
return id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment