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. --- gen.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'gen.cpp') diff --git a/gen.cpp b/gen.cpp index 4e19f84..952e3b5 100644 --- a/gen.cpp +++ b/gen.cpp @@ -2,15 +2,15 @@ #include #include #include "kgramstats.h" -#include #include -#include #include #include +#include int main(int argc, char** args) { - srand(time(NULL)); + std::random_device randomDevice; + std::mt19937 rng(randomDevice()); if (argc == 1) { @@ -73,7 +73,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; @@ -82,7 +83,7 @@ int main(int argc, char** args) std::cout << "Generating..." << std::endl; for (;;) { - std::string doc = kgramstats.randomSentence(140); + std::string doc = kgramstats.randomSentence(140, rng); doc.resize(140); std::cout << doc << std::endl; -- cgit 1.4.1