Well if your database is on a *NIX box you can just write a cron job to take care of the 24 thing. That's what cron jobs are for.
As for randomly selecting an image, do you have a unique ID on your images table? Is your unique ID sequential? If yes on both of these you could just select the min and max values and then use them in a randomizer to select a number between the 2 and finally use that number to select your image.
If you have ID's but that aren't sequential, then you could select them all into an array (which does have sequential ID's) and again use a randomizer to get a number between 1 and the count - 1 of the array and use the ID found there.
Finally if you don't have any unqiue ID's on your table does your database keep one for you (think Oracle's rownum)? If so then you can use that. Or if your database uses the LIMIT statement you can use that by getting the count() of rows then geting a random number between 1 and the count() and finally doing a select using the random number as the OFFSET in the LIMIT statement and getting only 1 row.
Thats all I can think of now, but if none of these seem to work then post your table structure and I'll see if I can see anything.