I use the following python script to choose a random background on login:

#!/usr/bin/python
import os, os.path, random, gconf
startdir="PUT YOUR FOLDER HERE"
gkey="/desktop/gnome/background/picture_filename"

imgs=[]
for root, dirs, files in os.walk(startdir):
  for file in files:
    base, ext = os.path.splitext(file)
    if ext.lower() in [".jpg", ".png", ".svg"]:
      imgs.append(os.path.join(root, file))

img = random.choice(imgs)

gconf.client_get_default().set_string(gkey, img)

It’s fairly simple, but shows the power of the python libraries. It “walks” the directory tree, collects all files of the given extensions, chooses one at random, then updates the gconf key for the Gnome background image.

P.S. Yes, I know a couple of ways to do that in a shell script, too. However, then one I used failed with whitespace in file names, so I decided to rewrite it in a much more sane language … the random involved was also a hack.