This is something that a friend of mine tried to setup several years ago; they wanted to have a random wallpaper appear automatically. This seems simple enough, but it turned out that Fedora didn't update the wallpaper if the file changed, which meant some kind of sneaky restarting of X11 services or something would have been needed for it to reload the wallpaper file. Or maybe it was actually easy to get around, but we gave up when simply copying a new image to have the same name and path as the current wallpaper didn't produce the desired result.
I noticed a few days ago that this functionality, intentional or not, exists in Ubuntu 8.04, possibly also in other versions I'm not sure. I created a script to do the wallpaper switch, it's pretty much hacked together over morning coffee, and keep in mind that I don't really know shell scripting that well. Anyway it doesn't really matter how ugly it is because it takes a fraction of a second to run and it works :)
You need to modify the change directory command so that it goes to whichever directory you want the random wallpaper to come from. The script will randomly take one image from this directory and name it current.jpg (the script assumes that all images are .jpg, if there are other types of files in the directory they will be ignored). As a preliminary step you should manually create a current.jpg in the directory and assign this to your wallpaper.
#!/bin/bash
cd /home/jonben/images/boardgame_paper
#find the number of images (potential wallpapers)
export n=`ls -l | grep jpg | grep -v current.jpg | wc -l`
#RANDOM is between 0 and 32767
export ran=$RANDOM
#choose one of the images randomly, NB integer division
export nran=`echo "scale=0; (($n*$ran)/32767) + 1" | bc`
#get the name of this file
export theone=`ls -1 | grep jpg | grep -v current.jpg | head -$nran | tail -1`
#make this file the current wallpaper
cp $theone current.jpg
If you want this code to run periodically then make an entry in your crontab. For example if you want it to switch backgrounds every day then enter something like:
00 02 * * * $HOME/bin/wallpaper_switch.sh
This will run the script 'wallpaper_switch.sh' (which I have put in the bin folder in my home directory) every day at 2am. Use 'teh google' if you want to learn how to use cronjobs, they can be pretty useful, especially for doing daily backups.
Here's one more version of the above which ensures that when run a different wallpaper will get chosen, the above is completely random and the new wallpaper could be the same as the old one...
#!/bin/bash
cd /home/jonben/images/boardgame_paper
#find the nuber of images (potential wallpapers)
export n=`ls -l | grep jpg | wc -l`
#ignore 2 files, the current.jpg and the corrisponding image
#i.e. we want the new wallpaper to be different
export n=`echo "scale=0; $n - 2" | bc`
#RANDOM is between 0 and 32767
export ran=$RANDOM
#choose one of the images randomly, NB integer division
export nran=`echo "scale=0; (($n*$ran)/32767) + 1" | bc`
#get the name of this file
export theone=`ls -1t | grep jpg | tail -$n | head -$nran | tail -1`
#make this file the current wallpaper
cp $theone current.jpg
#update time stamp on the used wallpaper
#so that it can be skipped next time
touch $theone