Skip to content

Instantly share code, notes, and snippets.

@nolim1t
Created July 26, 2022 08:25
Show Gist options
  • Save nolim1t/9ae47ed98c2b81c4eba60272cfbb1d40 to your computer and use it in GitHub Desktop.
Save nolim1t/9ae47ed98c2b81c4eba60272cfbb1d40 to your computer and use it in GitHub Desktop.
#!/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