Skip to content
Permalink
84895b0b30
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 83 lines (58 sloc) 2.42 KB
#!/usr/bin/perl -w
use Getopt::Long;
use constant USAGE => <<'eof';
usage: $0 [options]
--numberofwords -nw <n>: number of words
--enumerate -en <n>: create a list of arguments
eof
our %OPT;
my $opt_numberOfWords = 0;
my $opt_enumerate = 0;
GetOptions(
'numberofwords|nw=i' => \$opt_numberOfWords,
'enumerate|en=i' => \$opt_enumerate,
) or die USAGE;
my @WORDS
= ( "puk", "pukaak", "cluck", "cluckity", "bwak", "waak", "bok", "bwok", "cluck-a-buh-gawk", "cock-a-doodle-doo", "bwwwaak", "gobble", "honk");
my @PUNCTUATIONS = ( ".", "...", "!", "?" );
my @PARAGRAPH_SIZES = ( 15, 30, 75 );
my $enumerate = ($opt_enumerate) ? $opt_enumerate : 1;
for ( my $e = 0; $e < $enumerate; $e++ ) {
if ($opt_numberOfWords) {
$numberOfWords = $opt_numberOfWords;
}
else {
$numberOfWords = $PARAGRAPH_SIZES[ int( rand( scalar @PARAGRAPH_SIZES ) ) ];
}
# generate paragraph, with random words, capitalization, and punctuation.
my $paragraph = "";
my $previousWordHadPunctuation = 0;
for ( my $i = 0; $i < $numberOfWords; $i++ ) {
# pick a random word
my $word = $WORDS[ int( rand( scalar @WORDS ) ) ];
# magic multiplier
$word = join( "-", ($word) x ( 4 - int( ( log( rand(7) + 1 ) / log(2) ) + 1 ) ) );
# even more magical multiplier
$word =~ s/([aou]){2,}?/$1 x (rand(7)+1)/ge;
# optionally add punctuation
# note: always add punctuation if it's the last word.
my $shouldAddPunctuation = $i == $numberOfWords - 1 || rand() > 0.9;
my $punctuation = $shouldAddPunctuation ? $PUNCTUATIONS[ int( rand( scalar @PUNCTUATIONS ) ) ] : "";
$word = $word . $punctuation;
# optionally capitalize the word
# note: always capitalize if it's the first words, or if preceded by punctuation
my $shouldCapitalize = $i == 0 || $previousWordHadPunctuation || rand() > 0.7;
$word = $shouldCapitalize ? uc( substr( $word, 0, 1 ) ) . substr( $word, 1 ) : $word;
# preserve info for next iteration
$previousWordHadPunctuation = $shouldAddPunctuation;
# add word to paragraph
$paragraph = $paragraph . $word;
# if not last one, add a space
$paragraph = $i == $numberOfWords - 1 ? $paragraph : $paragraph . " ";
}
if ($opt_enumerate) {
printf "%d. ", $e + 1;
}
print $paragraph;
print "\n";
}