PDA

View Full Version : how random are the spotlights?


Joe Ross
01-11-2003, 01:55 PM
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
01-11-2003, 04:02 PM
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
01-11-2003, 05:34 PM
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
01-11-2003, 05:57 PM
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
01-11-2003, 06:00 PM
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
01-11-2003, 06:09 PM
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
01-11-2003, 06:12 PM
my bad. I'm just used to C's rand() that does nothing useful uless you seed it. Sorry about that.

AJ Quick
01-11-2003, 11:27 PM
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.