about summary refs log tree commit diff stats
path: root/gen.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 /gen.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 'gen.cpp')
-rw-r--r--gen.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/gen.cpp b/gen.cpp index 4e19f84..952e3b5 100644 --- a/gen.cpp +++ b/gen.cpp
@@ -2,15 +2,15 @@
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 <vector> 5#include <vector>
7#include <cstdlib>
8#include <fstream> 6#include <fstream>
9#include <iostream> 7#include <iostream>
8#include <random>
10 9
11int main(int argc, char** args) 10int main(int argc, char** args)
12{ 11{
13 srand(time(NULL)); 12 std::random_device randomDevice;
13 std::mt19937 rng(randomDevice());
14 14
15 if (argc == 1) 15 if (argc == 1)
16 { 16 {
@@ -73,7 +73,8 @@ int main(int argc, char** args)
73 size_t pos = form.find("$name$"); 73 size_t pos = form.find("$name$");
74 if (pos != std::string::npos) 74 if (pos != std::string::npos)
75 { 75 {
76 form.replace(pos, 6, fv_names[rand() % fv_names.size()]); 76 int fvInd = std::uniform_int_distribution<int>(0, fv_names.size()-1)(rng);
77 form.replace(pos, 6, fv_names[fvInd]);
77 } 78 }
78 79
79 return form; 80 return form;
@@ -82,7 +83,7 @@ int main(int argc, char** args)
82 std::cout << "Generating..." << std::endl; 83 std::cout << "Generating..." << std::endl;
83 for (;;) 84 for (;;)
84 { 85 {
85 std::string doc = kgramstats.randomSentence(140); 86 std::string doc = kgramstats.randomSentence(140, rng);
86 doc.resize(140); 87 doc.resize(140);
87 88
88 std::cout << doc << std::endl; 89 std::cout << doc << std::endl;