I'm trying to do a simple thing but run into a problem. All I want to do is pick a random 'userid' and display that on my page.

To come up with random number I do the following:

Code:
$res =& $mdb2->query('SELECT * FROM users');
$num = $res->numRows();
$random = (rand()%$num+1);
i.e. Get the number of rows in my table of users and then pick a random number from it.

However, I have noticed this isn't a good method since my 'userids' are not all sequential. For instance during testing etc. I have deleted id's 3, 4, 5, etc. So if I get random number 3, 4, ,5 etc. I end up with an error.

Is there a better way to select a random 'userid' from the ones which definitely exist?

* Also please note the code above uses PEAR MDB2 Class...