From fa26336b8b792a82349e89bcbf7b2c7833f7f420 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 8 Sep 2016 17:43:05 -0400 Subject: Improved randomization --- yandere.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'yandere.cpp') diff --git a/yandere.cpp b/yandere.cpp index 635b605..3cb5efa 100644 --- a/yandere.cpp +++ b/yandere.cpp @@ -1,7 +1,6 @@ #include #include -#include -#include +#include #include #include #include @@ -52,9 +51,6 @@ Container split(std::string input, std::string delimiter) int main(int argc, char** argv) { - srand(time(NULL)); - rand(); rand(); rand(); rand(); - YAML::Node config = YAML::LoadFile("config.yml"); twitter::auth auth; @@ -96,7 +92,10 @@ int main(int argc, char** argv) } } } - + + std::random_device random_device; + std::mt19937 random_engine{random_device()}; + for (;;) { std::cout << "Generating tweet" << std::endl; @@ -131,8 +130,10 @@ int main(int argc, char** argv) { result = "\n"; } else { - auto group = groups[canontkn]; - result = group[rand() % group.size()]; + auto& group = groups[canontkn]; + std::uniform_int_distribution dist(0, group.size() - 1); + + result = group[dist(random_engine)]; } if (!eqvarname.empty()) -- cgit 1.4.1