You can use rand() , but the performance is terrible.
select * from users order by rand() limit 5; <-- slow
I would suggest saving a list of all user identifiers in a serialization array and cache it in a disk file. (update periodically)
So you can un-serialize back using PHP and use PHP array_rand to select 5 random users.
To get the full information, you can do
select * from users where user_id in(...); <-- very fast
source share