Log in

View Full Version : how random are the spotlights?


Joe Ross
11-01-2003, 13:55
I seem to see the same quote by Dr. Bot "The big lesson we learned ... our past does not limit our future, that superior attitude will beat out big budgets." several times per session. I've even seen it on 3 consecutive pages. So...just how random are the spotlights?

Brandon Martus
11-01-2003, 16:02
SELECT * FROM cd_spotlight WHERE approved>0 ORDER BY RAND() LIMIT 1

I've found (and now you) that mysql rand() function isn't too random. I will be changing it slightly soon, to hopefully be a bit more random.


ok, its changed. Hopefully it'll be a bit more random.

AJ Quick
11-01-2003, 17:34
How did you change it? I noticed on one of my sites long ago that rand really doesn't work too well like that.

Brandon Martus
11-01-2003, 17:57
Pulled in the whole data set, didn't limit it to 1 row. I then used php's rand() function, and took a random number from 1->[# of records in dataset]. And then showed that row.

Hopefully random row of a randomly sorted dataset will be a bit more random. :D :shrug:

rbayer
11-01-2003, 18:00
Might you need to use srand (http://www.php.net/manual/en/function.srand.php)? Taking a random number twice won't do any good if it starts with the same seed value.

Brandon Martus
11-01-2003, 18:09
One's from mysql's 'ORDER BY RAND()', the other's from php's rand() function.

Oh, and from php.net's man page for srand().
Note: Since PHP 4.2.0 it's no longer necessary to seed the random number generator before using it.

rbayer
11-01-2003, 18:12
my bad. I'm just used to C's rand() that does nothing useful uless you seed it. Sorry about that.

AJ Quick
11-01-2003, 23:27
Originally posted by Brandon Martus
Pulled in the whole data set, didn't limit it to 1 row. I then used php's rand() function, and took a random number from 1->[# of records in dataset]. And then showed that row.

Ah, not that bad of a way to go that, just as long as it doesn't slow the site down too much. I don't know why they don't make that rand feature better with mySQL.. it is so useful.