I’m currently writting a very cool plugin/addon for wordpress. Therefor I needed a way to get a defined number of random posts.
And guess what? There is already a function providing this feature: get_posts()
To get 4 random posts just use this function call:
Since the argument orderby will be forwarded to the SQL statement, we will get 4 random posts from database. There are several more arguments, which can be found in the codex.