Extra Cheese

Me: Gary Bernhardt

Email: gary.bernhardt at gmail

Work: BitBacker

RSS Archive: 2008
2007
2006
Mar 14

The 13-Year-Old Equivalent of WS-*

One of the very first non-trivial programs I wrote was a game (of course), and it's hilarious to look back on it now. It was sort of like Dope Wars meets Choose Your Own Adventure, with a ton of 13-year-old humor thrown in. Even though I haven't seen it in ten years, there's one hilarious feature I remember very well.

Since it was a game (and not an abstract), it needed random numbers: you could buy and sell various illicit substances, and I needed to randomize the market prices. After stumbling around the VB docs for a while, I found the "Rnd" function, which returns a random float from 0 to 1. Obviously, I could generate random prices by doing this:

price = max_price * Rnd

Unfortunately, I didn't realize that. The example I saw for the "Rnd" function showed it being used like this:

value = Rnd
if value < 0.5 then
    'do the first thing
else
    'do the second thing
end if

Being the inexperienced pseudo-programmer that I was, I blindly copied the form of the example to suit my needs. My code went something like this:

value = Rnd
if value < 0.25 then
    price = 7
else if value < 0.5 then
    price = 12
else if value < 0.75 then
    price = 25
else
    price = 31
end if

I'm pretty sure there were only four cases, but there might've been eight. Either way, the limiting force for the number of cases was simple laziness. Maybe if I'd been less lazy, and added more cases, I would've noticed that I was moving toward n conditionals with a probability of 1/n each.

I like to think about stupid things like this for two reasons. First, it helps me keep at least a shred of humility about my abilities. In ten years, the software I'm writing now will probably also look ridiculous to me (but hopefully not this ridiculous). Second, this is a great example of missing the elegant solution and ending up with something big and gross. You might say it's the 13-year-old equivalent of WS-*.