A little note, this script wont work if there is less than the number specified in the $idsQuery. In this case the minimum number of quotes in the database for this script to work would be 8. And then, there would be nothing random about their selection, as after they have all been shown once, there will only be one to choose each time.
To make this script a little smarter, you could make the number of days that a quote cannot reappear in totalNumberOfQuotes/4 – so if there’s 8 quotes, one quote would not appear with less than 2 days since last time.
I would not do this dynamic limit thing myself, but it could potentially safe the day, if your friend chooses to delete most of his quotes one day, and gets below the magical limit.