#!/bin/sh
#
# gibberish.sh - Generate Burroughsesque text
# This script is in the PUBLIC DOMAIN
#
# Use: gibberish.sh [pmin] [pmax] [wordsmin] [wordsmax]
# pmin, pmax - Minumum and maximum # of paragraphs
# wordsmin, wordsmax - Minimum and maximum words per paragraph
# (not counting "of", "the", "and", "or", "but")
#
# Defaults: 3 8 30 130
#
export NPARMIN=3
export NPARMAX=8
export NWORDSPARMIN=30
export NWORDSPARMAX=130
if [ "$4" != "" ]; then
export NWORDSPARMAX=$4
fi
if [ "$3" != "" ]; then
export NWORDSPARMIN=$3
fi
if [ "$2" != "" ]; then
export NPARMAX=$2
fi
if [ "$1" != "" ]; then
export NPARMIN=$1
fi
if [ 0$NWORDSPARMAX -lt 0$NWORDSPARMIN ]; then
export NWORDSPARMAX=$NWORDSPARMIN
fi
if [ 0$NPARMAX -lt 0$NPARMIN ]; then
export NPARMAX=$NPARMIN
fi
export NWORDSPARRNG=$(($NWORDSPARMAX-$NWORDSPARMIN))
export NPARRNG=$(($NPARMAX-$NPARMIN))
awk '
BEGIN {
nwords = 0;
}
{
wlist[nwords++] = $0;
}
END {
srand();
npars = 3 + int(5 * rand());
npars = ENVIRON["NPARMIN"] + int(ENVIRON["NPARRNG"] * rand());
for (par = 0; par < npars; par++)
{
nwordspar = ENVIRON["NWORDSPARMIN"] + int(ENVIRON["NWORDSPARRNG"] * rand());
for (i = 0; i < nwordspar; i++)
{
thisword = wlist[int(nwords * rand())];
if (i > 0)
{
if (int(15 * rand()) == 8)
printf ". %s%s", toupper(substr(thisword,1,1)), substr(thisword,2);
else if (int(20 * rand()) == 19)
printf " of %s", thisword;
else if (int(20 * rand()) == 18)
printf " the %s", thisword;
else if (int(20 * rand()) == 17)
printf " and %s", thisword;
else if (int(20 * rand()) == 16)
printf " or %s", thisword;
else if (int(20 * rand()) == 15)
printf " but %s", thisword;
else
printf " %s", thisword;
}
else
printf "%s%s", toupper(substr(thisword,1,1)), substr(thisword,2);
}
printf ".\n\n";
}
}' < /usr/share/dict/words