diff --git a/include/generate.h b/include/generate.h index 863fe12..1f05bc3 100644 --- a/include/generate.h +++ b/include/generate.h @@ -1,3 +1,3 @@ #pragma once -void generate(short min_char_count, short max_char_count, short min_num_count, short max_num_count, int count); +void generate(short min_char_count, short max_char_count, short min_num_count, short max_num_count, int count, std::string seed); diff --git a/src/generate.cc b/src/generate.cc index f641dfe..5f9c84f 100644 --- a/src/generate.cc +++ b/src/generate.cc @@ -2,9 +2,19 @@ #include #include -void generate(short min_char_count, short max_char_count, short min_num_count, short max_num_count, int count) +void generate(short min_char_count, short max_char_count, short min_num_count, short max_num_count, int count, std::string seed) { - std::mt19937 engine(std::chrono::system_clock::now().time_since_epoch().count()); + std::mt19937 engine; + + if(seed != "") + { + std::seed_seq seq(seed.begin(),seed.end()); + engine.seed(seq); + } + else + { + engine.seed(std::chrono::system_clock::now().time_since_epoch().count()); + } std::uniform_int_distribution char_count_distribution(min_char_count, max_char_count); std::uniform_int_distribution char_distribution('a', 'z'); diff --git a/src/main.cc b/src/main.cc index 3a81bd5..91ddfb4 100644 --- a/src/main.cc +++ b/src/main.cc @@ -12,6 +12,7 @@ int main(int argc, char** argv) ("min-num", "The minimum number of digits", cxxopts::value()->default_value("0")) ("max-num", "The maximum number of digits", cxxopts::value()->default_value("4")) ("count", "How many usernames should be generated", cxxopts::value()->default_value("1")) + ("seed", "String used as seed sequence. If not defined, system time will be used instead.", cxxopts::value()->default_value("")) ("h,help", "Print help") ; @@ -28,6 +29,7 @@ int main(int argc, char** argv) short min_num = result["min-num"].as(); short max_num = result["max-num"].as(); int count = result["count"].as(); + std::string seed(result["seed"].as()); if(min_char > max_char) { @@ -53,6 +55,6 @@ int main(int argc, char** argv) return -1; } - generate(min_char, max_char, min_num, max_num, count); + generate(min_char, max_char, min_num, max_num, count, seed); return 0; }