id ahve all the anems in a database with a uniq ID
use ID as a auto_increasment Primary field
so somthing like
ID | Name
---+-----------------------------------
1 | Joe
2 | John
3 | Zully
and so on
then id just count the database get the amount of records and then use the rand() function
$var = rand(0,$database_count);
somthing like that