Quick actions

cmd+k|ctrl+k

Navigation

Languages

GodWords

Snippet info

Language

Bash

Visibility

public

Author

orph

Created

2024-04-27T15:13:51.099789Z

Updated

2024-04-27T15:20:43.014376Z

#!/bin/bash

# Function to generate a random word from the text.txt file
function generate_word() {
    local text_file="text.txt"
    local num_lines=$(wc -l < "$text_file")
    local random_line=$((RANDOM % num_lines + 1))
    sed -n "${random_line}p" "$text_file" | awk '{print $1}'  # Extract the first word from the line
}

# Function to generate a random sentence
function generate_sentence() {
    local num_words=$((RANDOM % 10 + 3))  # Generate a sentence with 3 to 12 words
    local sentence=""

    for ((i = 0; i < num_words; i++)); do
        local word=$(generate_word)
        # Capitalize the first word
        if [ "$i" -eq 0 ]; then
            word=$(echo "$word" | awk '{print toupper($0)}')
        fi
        sentence+=" $word"
    done

    echo "$sentence."
}

# Generate and output a random sentence
random_sentence=$(generate_sentence)
echo "$random_sentence"
INFO