Issue
Code backup
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Roll
|
||||
# This script returns the values and sum of a set of dice rolls. The first
|
||||
# arg is optional and gives a number of dice. The second arg is the number
|
||||
# of sides on the dice. For example "roll 2 6" will give two values from 1
|
||||
# to 6 and also returns their sum.
|
||||
#
|
||||
# (c)2009 Dominic Lepiane
|
||||
|
||||
sides=6
|
||||
dice=1
|
||||
total=0
|
||||
c=0
|
||||
|
||||
if [ $# = 2 ] ; then
|
||||
dice=$1
|
||||
sides=$2
|
||||
elif [ $# = 1 ] ; then
|
||||
sides=$1
|
||||
else
|
||||
echo "Usage: $0 [# of dice] <# of sides>" >&2
|
||||
exit -1
|
||||
fi
|
||||
|
||||
#echo "Rolling {$dice}d{$sides}"
|
||||
|
||||
while [ $c -lt $dice ] ; do
|
||||
c=$((c+1))
|
||||
roll=$((RANDOM%sides + 1))
|
||||
total=$((total+roll))
|
||||
echo -n "$roll "
|
||||
done
|
||||
|
||||
if [ $dice -gt 1 ] ; then
|
||||
echo -n " = $total"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
Reference in New Issue
Block a user