Skip to content

Instantly share code, notes, and snippets.

@Bombe
Created November 16, 2017 13:47
Show Gist options
  • Save Bombe/b7cff7918338a5056c1ce4957d8d7cc5 to your computer and use it in GitHub Desktop.
Save Bombe/b7cff7918338a5056c1ce4957d8d7cc5 to your computer and use it in GitHub Desktop.
Makes a decision between a number of given options.
#!/bin/bash
# 64D16CF7-35CB-4E1D-83E4-504260998EC4
numberOfChoices="${#@}"
if [ "${numberOfChoices}" == "0" ]; then
r="$((${RANDOM} % 2))"
if [ "${r}" == "0" ]; then
echo "No."
else
echo "Yes."
fi
elif [ "${numberOfChoices}" == "1" ]; then
r="$((${RANDOM} % 2))"
if [ "${r}" == "0" ]; then
echo "I would not choose ${1}."
else
echo "I would choose ${1}."
fi
else
r="$((${RANDOM} % ${numberOfChoices}))"
echo "I would choose ${@:$(($r+1)):1}."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment