Created
July 26, 2022 08:25
-
-
Save nolim1t/9ae47ed98c2b81c4eba60272cfbb1d40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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