Skip to content

Instantly share code, notes, and snippets.

@guimaluf
Created October 15, 2018 17:35
Show Gist options
  • Save guimaluf/611fd0db998b023abf31565aecce579d to your computer and use it in GitHub Desktop.
Save guimaluf/611fd0db998b023abf31565aecce579d to your computer and use it in GitHub Desktop.
Bash script to roll dices for D&D character sheet creation
#!/bin/bash
ATRIBUTOS=()
function remove_min {
local total=0
local dices=()
IFS=$'\n'
DICES=($(sort <<<"${ROLL[*]}"))
unset IFS
dices=${DICES[@]:1}
total=$(IFS='+';bc<<<"${DICES[*]:1}")
echo Dados: ${dices} = ${total}
ATRIBUTOS+=($total)
}
function dice_roll {
for i in $(seq 4);
do
ROLL[i]=$((${RANDOM}%6 +1))
done
echo ''
echo Rolagem: ${ROLL[@]}
}
echo ''
echo '### ROLAGENS ###'
for i in $(seq 6); do
dice_roll
remove_min
done
echo '#################'
echo ''
echo '### ATRIBUTOS ###'
echo $(IFS=$'\n'; sort <<<"${ATRIBUTOS[*]}")
echo '#################'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment