NaBloPoMo Code
Just in case there’s a fellow Linux geek out there that wants the code that pulls five random words from the standard word list that exists on most Linux (and Unix) boxes, here’s the Perl that I whipped up…
#!/usr/bin/perl
use strict;
$|++;
sub shuffle {
my $array = shift;
my $i;
for ($i = @$array; --$i; ) {
my $j = int rand ($i+1);
next if $i == $j;
@$array[$i,$j] = @$array[$j,$i];
}
}
print "Loading used words...";
my %usedwords = ();
open F, "used_words";
while () {
chomp;
$usedwords{$_} = 1;
}
close F;
print "DONE\n";
print "Loading dictionary...";
my @allwords = ();
open F, "/usr/share/dict/words";
while () {
chomp;
next if (defined($usedwords{$_}));
push @allwords, $_;
}
close F;
print "DONE\n";
print "Shuffling dictionary...";
shuffle(@allwords);
print "DONE\n";
print "Finding words...";
my @words = ();
foreach my $count (1..5)
{
push @words, $allwords[$count];
}
print "DONE\n";
my $print_words = join "\n", @words;
$print_words .= "\n";
print "Saving words to used words list...";
open F, ">> used_words";
print F $print_words;
close F;
print "DONE\n";
print "\nRandom Words:\n";
print $print_words;
Enjoy!
PS: Use at your own risk. I accept no responsibility for the use (or misuse) of this code. This code is guaranteed to do nothing more than take up space on your hard drive. If it eats other files, formats your hard drive, installs a rootkit, cures cancer, or destroys the world, then it’s not my fault.