Loop 1 user randomly

I found a realy great solition here. !!

It is a function that kindof ‘adds’ 'orderby' => 'rand' as a parameter.
What it does it that when someone uses that parameter, the function will query the database using regular MySQL, where random is always possible 🙂

The function:

// put this in your functions.php
add_filter('pre_user_query', function(&$query) {
   if($query->query_vars["orderby"] == 'rand') {
       $query->query_orderby = 'ORDER by RAND()';
   }
});

The loop will be something like:

// Query will look like this:
$args = array('orderby' => 'rand', 'number' => 5);

$users = WP_User_Query($args);