diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-28 20:28:20 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-28 20:28:20 -0500 |
commit | d7e934156858287cdb7597ad0dced97d4d279f2f (patch) | |
tree | e1822649bb449d972839bb5c8adfd6b1c51d652c /histogram.cpp | |
parent | b85830e8a852392036a803b7f6bb417c28ff17c4 (diff) | |
download | aspartame-d7e934156858287cdb7597ad0dced97d4d279f2f.tar.gz aspartame-d7e934156858287cdb7597ad0dced97d4d279f2f.tar.bz2 aspartame-d7e934156858287cdb7597ad0dced97d4d279f2f.zip |
Got it bot-ready!
Using C++ randomization now, along with an update to rawr-ebooks that allows it to do the same. Cleaned up the code here and there. Added in the twitter client and the config file reader. We can use librawr's histogram class now, so we don't need our own. Also why did we not name this bot "aspartame". It's a Sugar replacer. Hahaha. I'm Pink Diamond.
Diffstat (limited to 'histogram.cpp')
-rw-r--r-- | histogram.cpp | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/histogram.cpp b/histogram.cpp deleted file mode 100644 index 38fca45..0000000 --- a/histogram.cpp +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | #include "histogram.h" | ||
2 | #include <cstdlib> | ||
3 | #include <iostream> | ||
4 | |||
5 | template <class T> | ||
6 | void histogram<T>::add(const T& inst) | ||
7 | { | ||
8 | freqtable[inst]++; | ||
9 | } | ||
10 | |||
11 | template <class T> | ||
12 | void histogram<T>::compile() | ||
13 | { | ||
14 | distribution.clear(); | ||
15 | |||
16 | int max = 0; | ||
17 | for (auto& it : freqtable) | ||
18 | { | ||
19 | max += it.second; | ||
20 | distribution.emplace(max, it.first); | ||
21 | } | ||
22 | |||
23 | freqtable.clear(); | ||
24 | } | ||
25 | |||
26 | template <class T> | ||
27 | const T& histogram<T>::next() const | ||
28 | { | ||
29 | int max = distribution.rbegin()->first; | ||
30 | int r = rand() % max; | ||
31 | |||
32 | return distribution.upper_bound(r)->second; | ||
33 | } | ||
34 | |||
35 | template <class T> | ||
36 | void histogram<T>::print() const | ||
37 | { | ||
38 | for (auto& freqpair : freqtable) | ||
39 | { | ||
40 | std::cout << freqpair.first << ": " << freqpair.second << std::endl; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | template class histogram <unsigned long>; | ||