about summary refs log tree commit diff stats
path: root/ebooks.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2019-02-28 20:12:45 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2019-02-28 20:12:45 -0500
commit01fcbeb60da0bff33d5d9f5b870d444cc418a01d (patch)
treee506e532c02d08505d4328df37f4fac8c816e89f /ebooks.cpp
parent1890eb5d4a496aea5e9114550081ca63bd280f3b (diff)
downloadrawr-ebooks-01fcbeb60da0bff33d5d9f5b870d444cc418a01d.tar.gz
rawr-ebooks-01fcbeb60da0bff33d5d9f5b870d444cc418a01d.tar.bz2
rawr-ebooks-01fcbeb60da0bff33d5d9f5b870d444cc418a01d.zip
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.
Diffstat (limited to 'ebooks.cpp')
-rw-r--r--ebooks.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/ebooks.cpp b/ebooks.cpp index 0644132..3918b78 100644 --- a/ebooks.cpp +++ b/ebooks.cpp
@@ -2,8 +2,6 @@
2#include <list> 2#include <list>
3#include <map> 3#include <map>
4#include "kgramstats.h" 4#include "kgramstats.h"
5#include <ctime>
6#include <cstdlib>
7#include <fstream> 5#include <fstream>
8#include <iostream> 6#include <iostream>
9#include <twitter.h> 7#include <twitter.h>
@@ -11,14 +9,15 @@
11#include <thread> 9#include <thread>
12#include <chrono> 10#include <chrono>
13#include <algorithm> 11#include <algorithm>
12#include <random>
14 13
15const auto QUEUE_TIMEOUT = std::chrono::minutes(1); 14const auto QUEUE_TIMEOUT = std::chrono::minutes(1);
16const auto POLL_TIMEOUT = std::chrono::minutes(5); 15const auto POLL_TIMEOUT = std::chrono::minutes(5);
17 16
18int main(int argc, char** args) 17int main(int argc, char** args)
19{ 18{
20 srand(time(NULL)); 19 std::random_device randomDevice;
21 rand(); rand(); rand(); rand(); 20 std::mt19937 rng(randomDevice());
22 21
23 YAML::Node config = YAML::LoadFile("config.yml"); 22 YAML::Node config = YAML::LoadFile("config.yml");
24 int delay = config["delay"].as<int>(); 23 int delay = config["delay"].as<int>();
@@ -72,7 +71,8 @@ int main(int argc, char** args)
72 size_t pos = form.find("$name$"); 71 size_t pos = form.find("$name$");
73 if (pos != std::string::npos) 72 if (pos != std::string::npos)
74 { 73 {
75 form.replace(pos, 6, fv_names[rand() % fv_names.size()]); 74 int fvInd = std::uniform_int_distribution<int>(0, fv_names.size()-1)(rng);
75 form.replace(pos, 6, fv_names[fvInd]);
76 } 76 }
77 77
78 return form; 78 return form;
@@ -92,12 +92,12 @@ int main(int argc, char** args)
92 92
93 if (currentTime >= genTimer) 93 if (currentTime >= genTimer)
94 { 94 {
95 std::string doc = kgramstats.randomSentence(140); 95 std::string doc = kgramstats.randomSentence(140, rng);
96 doc.resize(140); 96 doc.resize(140);
97 97
98 postQueue.emplace_back(std::move(doc), false, 0); 98 postQueue.emplace_back(std::move(doc), false, 0);
99 99
100 int genwait = rand() % delay + 1; 100 int genwait = std::uniform_int_distribution<int>(1, delay)(rng);
101 101
102 genTimer = currentTime + std::chrono::seconds(genwait); 102 genTimer = currentTime + std::chrono::seconds(genwait);
103 } 103 }
@@ -125,7 +125,7 @@ int main(int argc, char** args)
125 && tweet.getAuthor() != client.getUser()) 125 && tweet.getAuthor() != client.getUser())
126 { 126 {
127 std::string doc = tweet.generateReplyPrefill(client.getUser()); 127 std::string doc = tweet.generateReplyPrefill(client.getUser());
128 doc += kgramstats.randomSentence(140 - doc.length()); 128 doc += kgramstats.randomSentence(140 - doc.length(), rng);
129 doc.resize(140); 129 doc.resize(140);
130 130
131 postQueue.emplace_back(std::move(doc), true, tweet.getID()); 131 postQueue.emplace_back(std::move(doc), true, tweet.getID());