March 20, 2009
MarkBernstein.org
 
Follow me on Twitter

Random Word Of The Day

Random Word Of The Day

Matt Hanlon takes up the Word Of The Day dashboard item. But he didn’t want to hunt up a bunch of “interesting” words. Instead, he has Tinderbox ask the built-in dictionary for a random word.

Matt wants to do this with a perl one-liner. So avoid getting tangled up with escaped quotes, we're going to store that one-liner in a user attribute called "command".

command: perl -e 'open IN, "</usr/share/dict/words";rand($.) < 1 && ($n=$_) while <IN>;print $n'

In essence, this leafs through the dictionary while rolling lots of dice; when the dice come up snake-eyes, we stop and choose that word.

And our action becomes:

Rule:if($Date!="today"){$Text=runCommand($command);$Date="today"}

<hr>

Want to do it in ruby?

command: ruby -e 'rand < 1.0/$. and line = $_ while gets; puts line.chomp if line' /usr/share/dict/words