summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;