From 01fcbeb60da0bff33d5d9f5b870d444cc418a01d Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 28 Feb 2019 20:12:45 -0500 Subject: Converted to C++ style randomization The logic in rawr::randomSentence with the cuts might be slightly different now but who even knows what's going on there. --- ebooks.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ebooks.cpp') diff --git a/ebooks.cpp b/ebooks.cpp index 0644132..3918b78 100644 --- a/ebooks.cpp +++ b/ebooks.cpp @@ -2,8 +2,6 @@ #include #include #include "kgramstats.h" -#include -#include #include #include #include @@ -11,14 +9,15 @@ #include #include #include +#include const auto QUEUE_TIMEOUT = std::chrono::minutes(1); const auto POLL_TIMEOUT = std::chrono::minutes(5); int main(int argc, char** args) { - srand(time(NULL)); - rand(); rand(); rand(); rand(); + std::random_device randomDevice; + std::mt19937 rng(randomDevice()); YAML::Node config = YAML::LoadFile("config.yml"); int delay = config["delay"].as(); @@ -72,7 +71,8 @@ int main(int argc, char** args) size_t pos = form.find("$name$"); if (pos != std::string::npos) { - form.replace(pos, 6, fv_names[rand() % fv_names.size()]); + int fvInd = std::uniform_int_distribution(0, fv_names.size()-1)(rng); + form.replace(pos, 6, fv_names[fvInd]); } return form; @@ -92,12 +92,12 @@ int main(int argc, char** args) if (currentTime >= genTimer) { - std::string doc = kgramstats.randomSentence(140); + std::string doc = kgramstats.randomSentence(140, rng); doc.resize(140); postQueue.emplace_back(std::move(doc), false, 0); - int genwait = rand() % delay + 1; + int genwait = std::uniform_int_distribution(1, delay)(rng); genTimer = currentTime + std::chrono::seconds(genwait); } @@ -125,7 +125,7 @@ int main(int argc, char** args) && tweet.getAuthor() != client.getUser()) { std::string doc = tweet.generateReplyPrefill(client.getUser()); - doc += kgramstats.randomSentence(140 - doc.length()); + doc += kgramstats.randomSentence(140 - doc.length(), rng); doc.resize(140); postQueue.emplace_back(std::move(doc), true, tweet.getID()); -- cgit 1.4.1