Something Random This Way Comes
By Randal L. Schwartz
Sure, there are random link scripts and random "quote-of-the-day" scripts out there. But I wanted to tackle the subject and give it a twistsome memory. The random program I'll describe here "knows" what random items have been given out recently, and biases older items with a higher probability of being selected. My random program does it in a way that allows a large number of entries to run in parallel, not tying up a central database while making a decision. "Cool," you say? Read on!
Not only that, the program could be easily used for random links, random ads (bleh, but they pay the bills for the coolest free sites), or even just random graphics. So how much would you pay? It's free, and can be found in
Listing One. Much of it is commented, but let me hit the high points.
Random Thoughts
The first two lines in
Listing One begin nearly every program I write these days. Line 1 enables taint checks and warnings, while line 2 forces me to think about the variables I am using and why. Line 3 brings in a neat utility module that I use to get the directory part (dirname) and file part (basename) of some of the UNIX paths and URLs.