Ummm...well yeah, that's what your query asked for.
Code:
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
Code:
ORDER BY RAND() LIMIT 10
And then you will not need or want that ugly
generate_random_array( ) function. The records *WILL* be in random order, already.