summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2015-05-20 19:01:44 +0100
committerJoe Robinson <joe@lc8n.com>2015-05-20 19:01:44 +0100
commitdd193f5875caefff10f90a57a2830f66043c76d1 (patch)
treec7c80345e7fadf97bbf4ad6fe591e49ed04d0b07
parente0c13d3ade199417952c9b31c97e8e1bb39aab0b (diff)
Added option to make a random selection from a listHEADmaster
-rw-r--r--blarandom.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/blarandom.cpp b/blarandom.cpp
index 894d47a..228c58a 100644
--- a/blarandom.cpp
+++ b/blarandom.cpp
@@ -34,6 +34,7 @@
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
*/
@@ -41,12 +42,12 @@
#include <sstream>
#include <climits>
#include <string>
-
+#include <stdio.h>
#include <RandomLib/Random.hpp>
int main() {
- std::string version = "0.8.1";
+ std::string version = "0.9";
RandomLib::Random r; // Create r
r.Reseed(); // and give it a unique seed
@@ -72,7 +73,7 @@ int main() {
}
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" << std::endl;
+ 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;
}
@@ -98,6 +99,7 @@ int main() {
bool d20 = false;
bool wolf = false;
bool internet = false;
+ bool custom = false;
if (args[0].empty()) {
min = 1;
max = 10;
@@ -144,6 +146,24 @@ int main() {
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) {
@@ -340,6 +360,8 @@ std::string theInternetList[19] = {
strResult = theBlueList[intResult];
} else if (internet) {
strResult = theInternetList[intResult];
+ } else if (custom) {
+ strResult = args[intResult];
} else {
std::stringstream ss;
ss << intResult;