PDA

View Full Version : MySQL RANDOM Question


Boofo
01-22-2003, 01:42 AM
I just found this message on the mysql site:

As of MySQL 3.23.52, MySQL changed the way
RAND() functions, such that you MUST supply a
SEED to get an actual random number. If you do
not, each new connection will return close to the
same number as the previous new connection. An
example to test this would be to run the follow
command multiple times in a row. mysql -u
username -p -e'select rand()' A basic way to seed
this would be to run RAND(NOW()).

If I change this:

SELECT quote,name FROM quotes ORDER BY rand() LIMIT 1

to this:

SELECT quote,name FROM quotes ORDER BY RAND(NOW()) LIMIT 1

will it give me a more random quote than it does now? It seems to diplay the same quote every 20 or so times, right now.

They are running MySQL v3.23.54 on the server, by the way.

Xenon
01-22-2003, 11:32 AM
yes, seems that was meant by mysql devs ;)

use Rand(now()).

Boofo
01-22-2003, 11:50 AM
Since I have been using it (for the last 12 hours or so), I haven't had a single repeat on the quotes. It seems to randomize them a little better.