That probably could be better put as:
$result = mysql_query("SELECT COUNT(*) FROM tablename");
if (($numrows = mysql_result($result, 0)) > 0) {
$rand = mt_rand(0, $numrows - 1);
$result = mysql_query("SELECT * FROM tablename LIMIT $rand, 1");
} else {
//no data to retrieve
}
But yeah, how are you using MySQL's RAND()?