Ummm...well yeah, that's what your query asked for.
ORDER BY emailed_value desc, rating_value DESC limit 0, $display_nr";
Apparently, you want the more "important" jokes (by emailed_value, whatever that is, and then by rating_value). If you truly want random jokes, than you need to abandon the use of those "importance" qualifiers.
So just change it to
ORDER BY RAND() LIMIT 10
And then you will not need or want that ugly
function. The records *WILL* be in random order, already.