summaryrefslogtreecommitdiff
path: root/blarandom.cpp
blob: 228c58aad7268b30be6a60ba5c17af2f4e6dac25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*

    Copyright 2012 Blatech <http://www.blatech.co.uk>
    Author: Joe Robinson <joe@lc8n.com> (JR)
    	Co-Author: Phil Burton <philbeansburton@gmail.com> (PGB)

    Changelog:

    v0.1    -   Initial release (JR)
    v0.2    -	Added Makefile (JR)
    v0.3    -	Added help (JR)
    v0.31   -	Changed help description (JR)
    v0.4    -   Added coin & dice presets (JR)
    v0.5    -   Added 8ball preset (JR)
    v0.6    -   Can now use count with presets (JR)
    v0.61   -   Added error handling for 8ball, removed ability to count (JR)
    v0.62   -   Fixed 8ball handling more than one word (JR)
    v0.7    -   Added thebluelist (this should really be a separate file) (JR)
    v0.71   -   Added more thebluelist options (JR)
    v0.8    -   Added 'internet' function (PGB)
    v0.81   -   Changed max value for 'interent' array to 18.
    v0.9    -   Added option to make a random selection from a list
*/


#include <iostream>
#include <sstream>
#include <climits>
#include <string>
#include <stdio.h>
#include <RandomLib/Random.hpp>

int main() {

    std::string version = "0.9";

    RandomLib::Random r;          // Create r
    r.Reseed();                   // and give it a unique seed
    char input[1000];
    const int N_ARGS = 30;
    fgets(input, 1000, stdin);
    std::string strInput = input;
    std::string args[N_ARGS] = { "" };

    std::istringstream iss(strInput);

    int min = INT_MIN;
    int max = INT_MIN;
    int count = 1;    
    
    for(int i = 0; i < N_ARGS; i++) {
        iss >> args[i];
    }

    if (!args[0].compare("-v") || !args[0].compare("--version")) {
        std::cout << "v" << version << std::endl;
        return 0;
    }

    if (!args[0].compare("-h") || !args[0].compare("--help")) {
   	    std::cout << "Usage: !random [minimum bound] [maximum bound] [count] | Examples: !random : returns a number from 1 to 10 inclusive | !random 20 : Returns a number from 1 to 20 inclusive | !random 10 20 : Returns a number from 10 to 20 inclusive | !random 1 10 3 : Returns 3 random numbers from 1 to 10 inclusive | !random [option1] [option2] [option3...] : Return a random result from the options given" << std::endl;
        return 0;
    }

    
    if (args[2].empty()) {
        count = 1;
    } else {
        count = atoi(args[2].c_str());
    }
    
    if (args[1].empty()) {
        max = atoi(args[0].c_str());
        min = 1;
    } else {
        max = atoi(args[1].c_str());
        min = atoi(args[0].c_str());
    }

    bool coin = false;
    bool letter = false;
    bool eightball = false;
    bool dice = false;
    bool d20 = false;
    bool wolf = false;
    bool internet = false;
    bool custom = false;
    if (args[0].empty()) {
        min = 1;
        max = 10;
    } else if (!args[0].compare("dice") || !args[0].compare("die")) {
        min = 1;
        max = 6;
        dice = true;
    } else if (!args[0].compare("coin")) {
        min = 0;
        max = 1;
        coin = true;
    } else if (!args[0].compare("d20")) {
        min = 1;
        max = 20;
        d20 = true;
    } else if (!args[0].compare("letter") || !args[0].compare("letter")) {
        min = 0;
        max = 25;
        letter = true;
    } else if (!args[0].compare("8ball")) {
        min = 0;
        max = 17;
        count = 1;
        eightball = true;
        std::string question = "";
        for (int i = 1; i < N_ARGS; i++) {
            question += args[i];
        }
        if (question.length() > 0) {
            if (question.substr(question.length()-1, 1).compare("?")) {
                std::cout << "Ask a question!" << std::endl;
                return 1;
            }
        } else {
            std::cout << "Ask a question!" << std::endl;
            return 1;
        }
        
    } else if (!args[0].compare("wolf")) {
        min = 0;
        max = 120;
        wolf = true;
    } else if (!args[0].compare("internet")) {
     	min = 0;
     	max = 18;
     	internet = true;
    } else {
        int isNum = true;
        for (int i = 0; i < args[0].length(); i++) {
            if (!isdigit(args[0][i])) {
                isNum = false;
            }
        }
        if (!isNum) {
            min = 0;
            for (int i = 0; i < N_ARGS; i++) {
                if (!args[i].empty()) {
                    max++;
                }
            }
            max--;
            count = 1;
            custom = true;
        }
    }
    
    if (coin || dice || letter || d20 || wolf || internet) {
        if (args[1].empty()) {
            count = 1;
        } else {
            count = atoi(args[1].c_str());
        }
    }

    int intResult = 0;
    std::string strResult = "";
    char letters[26] = { 'A','B','C','D','E','F','G','H','I','J','K',
                         'L','M','N','O','P','Q','R','S','T','U','V',
                         'W','X','Y','Z' };
    std::string eightBallStr[18] = { "Yes.",
                        "No.",
                        "Outlook so so.",
                        "Absolutely.",
                        "My sources say no.",
                        "Yes definitely.",
                        "Very doubtful.",
                        "Most likely.",
                        "Forget about it.",
                        "Are you kidding?",
                        "Go for it.",
                        "Not now.",
                        "Looking good.",
                        "Who knows.",
                        "A definite yes.",
                        "You will have to wait.",
                        "Yes, in due time.",
                        "I have my doubts." };

    std::string theBlueList[121] = { 
"Geolocate somebody on the internet and see whether we can convince them to meet us at local bars/restaurants",
"Smash a glass over somebody's hand",
"The piano room",
"pee in bush",
"sex in toilets",
"sex outside lemmy",
"writing on wall",
"lots of people in a phone box",
"lose important stuff",
"a thousand jager trains in a day",
"go to exmouth, on a train, drinking special brew",
"special brew",
"guitar hero",
"Punch bag",
"Blue room drinking",
"bottle of whisky for a single person",
"epic amounts of Jugs of sangria",
"Knob on",
"cock or ball",
"Talking to Jen",
"yard of gravy",
"long pour",
"play in park",
"straight arm a pitcher!",
"ben getting naked everywhere",
"Somebody should break their wrist!",
"climbing over bus stop",
"breaking a piece of machinery somewhere on campus",
"pooing in a random toilet in the building",
"Stealing a sign and throwing it down the lift shaft",
"snorting pro plus",
"TAG TEAM VOMITING",
"Going under the Libray",
"Getting into some sort of void of stairs in the ram building..somewhere",
"throwing a glass out a window",
"Vomiting on the Royal Albert Memorial museum",
"flushing a shoe in a toilet",
"*falling* through a very muddy field",
"throwing phones at and into all kinds of things and places",
"buying an innumerable quantity of popplers",
"being unsuitable around jen",
"putting on absolutely fucking HUGE amounts of ram music",
"pissing in a sink in a random sink in the building",
"pissing in a bin with at least one other person",
"doing silly things to people who are sleeping",
"bon going mental on the roundabout",
"go to every pub in exeter",
"anger summer",
"RUINING nandos",
"get shouted at repeatedly in RUBY TUESDAY",
"buying 1000 frys from KFC then dropping them as we ran tot he train station",
"drink a mayonnaise shot",
"having an impy brekfast",
"staying awake 52 hours",
"having lots of living room breakfasts",
"sleeping in lots of pubs",
"BOWLING PLATTER.",
"sing shutupwomangetonmyhorse very loudly everywhere",
"take photos of intense marcus everywhere",
"steal some tyres and some cones, then roll the tyres down a road",
"set a tyre on fire",
"pizza hut all you can eat.",
"literally chunder everywhere",
"go to exmouth",
"THE VIPER",
"watch Rejected under the library",
"watch lost in translation",
"eat pizza in the blue room",
"drink in the blue room",
"DRINK WITH PETER KNAGGS",
"take pints to reverson's room",
"watch bicha muda repeatedly",
"Thank Sue Addo.",
"everyone needs to buy green tshirts from primark",
"hats.",
"the real mccoys",
"Lots of Wagamama.",
"I'm the batman!",
"EXMOUTH ARCADE.",
"crash a house party",
"Thank Sue Addo.",
"shout AAAAAAAAAAARRRRRRRRRGGGGGGGHHHHHH in a car",
"declare love to various barmaids",
"Listning to the classic project!!!",
"barbeque",
"steps place",
"Buy pillows",
"Get stupidly drunk",
"Get stupidly high",
"Drink blue/green stuff",
"Go to a sex show",
"LATER!",
"Eat Chipsy hotdog",
"Piss tornado",
"Run from the law",
"Drink tea",
"Cook bacon",
"Drink on a train",
"Drink under the sea",
"Go to arena",
"Talk to Jonny Mallett",
"Puke in a glass bin",
"Smash glasses under the table",
"Stare at the cathedral",
"Knob on cathedral",
"Running from burger king staff",
"Waiting for an automated pillar to rise out of the ground",
"Naked guitar hero",
"Skinny dipping",
"Falling down the stairs",
"Burning hair with poi",
"Feeding a horse",
"Stick a pillow to a wall with vomit",
"Getting stuck places",
"Puke on a church",
"Piss on a church",
"Get a taxi from RASHEED",
"Running into a sign at the same time",
"Standing in the most inappropriate place",
"Timepiece burger",
"Ram burger"
};

std::string theInternetList[19] = { 
"http://www.xkcd.com",
"http://www.thedailymash.co.uk",
"http://www.cad-comic.com/cad/",
"http://www.slashdot.org/",
"http://www.bbc.co.uk/news",
"http://www.thedailywtf.com",
"http://news.ycombinator.com",
"http://www.reddit.com/r/todayilearned",
"http://whatif.xkcd.com",
"http://www.w3schools.com",
"http://stackoverflow.com/questions/194812/list-of-freely-available-programming-books",
"http://andreehansson.se/the-basics-of-jquery/",
"http://tldp.org/LDP/tlk/tlk.html",
"http://www.regexpal.com/",
"http://git.or.cz/course/svn.html",
"http://try.github.com/",
"http://jsfiddle.net/",
"http://gskinner.com/RegExr/",
"http://www.jslint.com/"
};

    for (int i = 0; i < count; i++) {
        intResult = r.IntegerC(min, max);
        if (coin) {
            if (intResult == 1) {
                strResult = "H";
            } else {
                strResult = "T";
            }
        } else if (letter) {
            strResult = letters[intResult];
        } else if (eightball) {
            strResult = eightBallStr[intResult];
        } else if (wolf) {
            strResult = theBlueList[intResult];
        } else if (internet) {
            strResult = theInternetList[intResult];
        } else if (custom) {
            strResult = args[intResult];
        } else {
            std::stringstream ss;
            ss << intResult;
            strResult = ss.str();
        }
        std::cout << strResult << " ";        
    }

    std::cout << std::endl;
    
    return 0;

}