https://community.linuxmint.com/tutorial/view/997
as a base but used find instead of ls to recurse through subdirectories.
#!/bin/bash
while true;do
DIR="{your picture path}"
# Command to Select a random jpg file from directory recursively
PIC=$(find $DIR -name "*.jpg" -type f | grep jpg | shuf -n1)
# Set Background Image
gsettings set org.mate.background picture-filename "$PIC"
sleep 300
done