select * from table_name order by rand() limit 1;
is not the way to go! It's a performance killer as our poor database server has to generate random number for every row, sort the whole table by it and then just select the lucky row. There is a much better way to solve this, here's how I do it (in RoR):
Model.find :first, :offset => ( Model.count * rand ).to_i
This is much faster than the first method and no custom SQL queries! All this does is count number of rows in a table (very fast) and select one row at some offset while still having the table ordered by primary key (very fast).
Just test the 2 solutions on a large dataset and see for yourself.