This is a simple script that, when run, sets the background to a random picture in a directory. You can specify the directory and the filetype of the pictures by editing the variables at the top of the script. Put this code in a file named randbg.sh.
#!/bin/bash
IMAGE_DIRECTORY=/home/michael/img/wallpaper/current
FORMAT='*.jpg'
NUM_OF_IMAGES=`ls $IMAGE_DIRECTORY/$FORMAT | wc -l`
if [ $((NUM_OF_IMAGES)) -gt 0 ]
then
((N=RANDOM%NUM_OF_IMAGES+1))
IMAGES=`find $IMAGE_DIRECTORY -name "$FORMAT" -printf "%p\r"`
IMAGE=`echo $IMAGES | awk -F"\r" '{ print $(n) }' n=$N`
echo "Setting background to '$IMAGE'"
fbsetbg "$IMAGE"
fi
