well, it kind of depends.
here is probably the easiest solution:
perform a query to get all of the user_names / user_names that are logged in.
then just load these ids/names into an array, and generate a random number between 0 and sizeof(array of names). once you get 4 unique names from that array, spit them out.
here is the pseudocode/some code:
$query = "SELECT DISTINCT * FROM crib_users WHERE active='1'";
$user_array = array();
$i = 0;
$result = @mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$user_array[$i] = $row['user_name'];
$i++;
}
//here is where it will get a little tricky. you will want unique numbers,
//so if you get the same random number twice, you will have to disregard
//the second one.
$i = 0;
$rand_array = array();
while ($i < 4)
{
$random_num = rand(0, count($user_array));
if (!array_search($random_num, $rand_array))
{
$rand_array[$i] = $random_num;
$i++;
}
}
so at the end, the $rand_array should contain 4 unique user names. then do what you want with it.
hope you see where i was going with that. hope it helps.