ti hanno già risposto
SELECT id FROM $nometabella ORDER BY RAND()