summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--roll.php21
2 files changed, 22 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 8c1c72c..a6866ab 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,7 @@ BINFILES = \
arg \
ord \
urldecode \
+ roll \
v-www-browser \
v-editor \
whatismyip \
diff --git a/roll.php b/roll.php
new file mode 100644
index 0000000..0d8aa25
--- /dev/null
+++ b/roll.php
@@ -0,0 +1,21 @@
+#!/usr/bin/env php
+<?php
+
+$string = $argv[1];
+
+preg_match('/([0-9]*)d([0-9]+)(([+-][0-9]+))?/', $string, $matches);
+$dice = (int)$matches[1];
+$die_size = (int)$matches[2];
+$mod = (int)$matches[3];
+
+if ($dice<1) $dice = 1;
+
+$total = 0;
+for ($i=0; $i < $dice; $i++) {
+ $v = mt_rand(1, $die_size);
+ echo $v.'+';
+ $total += $v;
+}
+echo $mod;
+$total += $mod;
+echo ' = '.$total."\n";