#! /s/std/bin/perl

use CGI qw(:standard);

$DEFAULT = 3;
@counts = qw { Zero One Two Three Four Five Six Seven
		Eight Nine Ten };
$count = $ARGV[0];
$count || ($count = $DEFAULT);

$stringCount = $counts[$count];

unless ($stringCount) {
	$stringCount = $count;
}

$TITLE = "$stringCount Random Words";

print header, start_html($TITLE), h1($TITLE);
print hr;

$words = "/usr/share/dict/words";
$webster = "/s/std/bin/webster";

chomp($wordCount = `wc $words | awk '{print \$1}'`);

for ($i = 0; $i < $count; $i++) {
	$rand = int rand $wordCount;
	#print ("\$rand is $rand.\n");
	chomp ($word = `head -$rand $words | tail -1`);
	$def = `echo \"1\" | $webster $word`;
	if ($def =~ /No matches were found/) {
		$i--;
		next;
	}
	print "<FONT COLOR=\"#FF0000\" SIZE=+1>";
	print ("$word:\n");
	print "</FONT>";
	print "<pre>";
	print ($def);
	print "</pre>";
}	

print hr;
print "<A HREF=\"./randomWords.xcgi\">"
	  ."Get three new random words</A>.";
print br;
print "<A HREF=\"http://cs.wisc.edu/~johnbent\">Back to homepage</A>.";

print end_html;

