What about in MySQL:
SELECT personID from persons ORDER BY RAND(NOW()) LIMIT 1
If the table is large, then the following might be better:
LOCK TABLES foo READ;
SELECT FLOOR(RAND() * COUNT(*)) AS rand_row FROM foo;
SELECT * FROM foo LIMIT $rand_row, 1;
UNLOCK TABLES;
There's a whole discussion on
I made this code to pick a random record from a changeable number of
records in a given table.
I'm just curious if any of the more awake coders out there can see a way to
optimize this for better performance, since there's several other DB
queries on the same page.
$records =
2 matches
Mail list logo