feat: Added optional param for seed
This commit is contained in:
parent
d6e506eaeb
commit
0467f94fd3
@ -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);
|
||||
|
@ -2,9 +2,19 @@
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
|
||||
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<short> char_count_distribution(min_char_count, max_char_count);
|
||||
std::uniform_int_distribution<char> char_distribution('a', 'z');
|
||||
|
@ -12,6 +12,7 @@ int main(int argc, char** argv)
|
||||
("min-num", "The minimum number of digits", cxxopts::value<short>()->default_value("0"))
|
||||
("max-num", "The maximum number of digits", cxxopts::value<short>()->default_value("4"))
|
||||
("count", "How many usernames should be generated", cxxopts::value<int>()->default_value("1"))
|
||||
("seed", "String used as seed sequence. If not defined, system time will be used instead.", cxxopts::value<std::string>()->default_value(""))
|
||||
("h,help", "Print help")
|
||||
;
|
||||
|
||||
@ -28,6 +29,7 @@ int main(int argc, char** argv)
|
||||
short min_num = result["min-num"].as<short>();
|
||||
short max_num = result["max-num"].as<short>();
|
||||
int count = result["count"].as<int>();
|
||||
std::string seed(result["seed"].as<std::string>());
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user