diff options
Diffstat (limited to 'roll.php')
-rw-r--r-- | roll.php | 21 |
1 files changed, 21 insertions, 0 deletions
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"; |