Skip to content

Instantly share code, notes, and snippets.

@alexwilson
Created August 1, 2026 04:21
Show Gist options
  • Select an option

  • Save alexwilson/9069b5ca23ae6d7e7dd36d3bf291872e to your computer and use it in GitHub Desktop.

Select an option

Save alexwilson/9069b5ca23ae6d7e7dd36d3bf291872e to your computer and use it in GitHub Desktop.
genhostname.sh
genhostname() {
local words=${1:-4}
local dict=${DICT:-/usr/share/dict/words}
local result=""
for i in $(seq 1 "$words"); do
lines=$(wc -l < "$dict")
rand=$(openssl rand 4 | od -An -tu4 | tr -d ' ')
index=$(( rand % lines + 1 ))
word=$(sed -n "${index}p" "$dict" | tr 'A-Z' 'a-z' | tr -cd 'a-z')
result="${result}${word}-"
done
num=$(openssl rand 2 | od -An -tu2 | tr -d ' ')
echo "${result}${num}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment