diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-08-04 19:32:50 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-08-04 19:32:50 -0400 |
commit | 01413023fcd6a87159b43bd5a80b9848bbe50bd6 (patch) | |
tree | fdda52a3caa3276672b01121856c32ed32f6b8fd | |
parent | 4dcae3738b30dc14812a6dc27684c66fd20141ec (diff) |
I wrote a "roll" tool to use while playing Dungeons and Dragons.
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | roll.php | 21 |
2 files changed, 22 insertions, 0 deletions
@@ -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"; |