Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
getArray() {
array=()
while IFS= read -r line
do
array+=("$line")
done < "$1"
}
# Read "tickets.txt" into a variable called $array
# Grab length of array and then grab a random number
getArray "tickets.txt"
i=0
for e in "${array[@]}"
do
i=$(echo "$i + 1" | bc)
done
RAND=$((1 + $RANDOM % $i))
SELECTION=$(echo "$RAND - 1" | bc)
echo "The winner is: ${array[$SELECTION]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment