-
-
Save fry69/7a29bbedb03e390e186867b8f05c9455 to your computer and use it in GitHub Desktop.
Filesystem Russian Roulette
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
#!/usr/bin/env bash | |
# File to store previously chosen numbers | |
HISTORY_FILE="roulette_history.txt" | |
# Create the file if it doesn't exist | |
if [[ ! -f $HISTORY_FILE ]]; then | |
touch $HISTORY_FILE | |
fi | |
# Load previously chosen numbers into an array | |
mapfile -t chosen_numbers < $HISTORY_FILE | |
# Generate a random number from 1 to 6 that hasn't been chosen before | |
while true; do | |
random_number=$((RANDOM % 6 + 1)) | |
if ! [[ " ${chosen_numbers[*]} " =~ " $random_number " ]]; then | |
break | |
fi | |
done | |
# Handle the deadly case | |
if [[ $random_number -eq 6 ]]; then | |
echo "😱 Russian roulette result: $random_number" | |
echo "Deleting filesystem... rm -rf / --no-preserve-root" | |
echo "Just kidding! Your files are safe... for now. 😈" | |
else | |
# Add the number to the history file | |
echo $random_number >> $HISTORY_FILE | |
echo "😌 Russian roulette result: $random_number. You're safe... for now." | |
fi | |
# Display previously chosen numbers | |
echo "Previously chosen numbers: ${chosen_numbers[*]} $random_number" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment