Randoword.sh

Posted on October 30, 2006

I’ve had variations of this script kicking around in my .bash_history for quite some time now. The first version of it merely printed a random word from my dictionary file at a rate of one per second. This served as a source of inspiration/entropy for irc conversations and Flickr titles. Today, I decided to extend this one-liner to generate eight-words-at-a-time at a variable rate and jigger the output into an irssi process to amuse the good netizens. Here is the implementation for randoword.sh.


#!/bin/sh
i=0
while true; do
  let i=$i+1
  dictionary="/usr/share/dict/linux.words"
  dl=($(wc -l $dictionary))
  echo -n "randowords #$i: "
  for j in $( seq 1 8 ); do
    head -n$(($(head -c4 /dev/urandom | od -An -tu4) % $dl))\
    $dictionary| tail -n1
  done | xargs
  sleep $((RANDOM % 3600))
done

Update: I never really understood how to use random numbers within a bash script without invoking perl (or equivalent). In light of _fool’s comment, I rewrote my script using only bash and POSIX commands. I had to break-out /dev/urandom and od because bash’s $RANDOM variable only produces random values up to 32767. Technically, it’d be a whole lot faster for a C program to use a pointer to jump around randomly in the dictionary, but that seems too much like work.

Update 2: The seq command probably isn’t POSIX.

Update 3: In Ruby: ruby -e ' $w=STDIN.readlines; 8.times{print "#{$w[rand(483523)].chomp} "}' < /usr/share/dict/linux.words

New Versions of the Web

Posted on October 20, 2006

I wish I could could claim this as my own, but this one comes from infamous footballer, Gabriel Jones. This is what we in the business refer to as “pure genius”.

Web 2.0 — you know it, you got it –> basically junk

Web 3.5 — all 5 senses enabled via appropriate tech software and hardware

Web 4.0 — all 5 senses enabled to viewer, plus virtual intimacy (with bouncer present of course)

Web 6.0 — 6 senses enabled to viewer, plus virtual intimacy (no bouncer present) and ability to see dead people

Cinnamon Toast Equations

Posted on October 06, 2006

Infamous civil engineering juggernaut Jeremy Ghent sent this one to me o’er the Intarweb.

Variables:
A = Roommate 1
B = Roommate 2
C = Neighborly Fellow
D = Sugar
E = Bread
F = Milk
G = Cinnamon
H = Messy Sugary-Cinnamony Outline

‘A’ enters residence of ‘C’. ‘A’ complains that ‘B’ is eating his food. ‘A’ is certain because he keeps cleaning up ‘H’. And ‘B’ has never purchased ‘D’, ‘E’, or ‘G’. ‘A’ proceeds to complain that his ‘F’ is nearly empty and ‘A’ has not had any all week -> ‘B’ must be consuming ‘A’s ‘D’,'E’,'F’,and ‘G’ and leaving ‘H’ for ‘A’ to clean up. ‘A’ leaves residence of ‘C’ and proceeds to residence of ‘A’ + ‘B’. 147 sec later ‘B’ enters residence of ‘C’. ‘B’ states “Man ‘A’ is pissed off and I didn’t even do anything.” ‘C’ inquires as to the circumstances. ‘B’ states “‘A’ just walked in saw me and went to his room and slammed the door. ‘C’ asks what ‘B’ was doing at the time ‘A’ entered. ‘B’ responds ” Nothing I was just standing there eating cinnamon toast and drinking a glass of milk.” ‘C’ just shrugs shoulders and contains violent laughter.

Please solve for ‘B’ (Hint: ‘B’ likes to call dogs cats, is known to play drums, is generally noisy, has recently taken a liking to artificial water foul and apparently has the occasional hankering for Sugary-Cinnamony Goodness)