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?
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.
[EDIT]ok, its changed. Hopefully it’ll be a bit more random.[/EDIT]
How did you change it? I noticed on one of my sites long ago that rand really doesn’t work too well like that.
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. :shrug:
Might you need to use srand? Taking a random number twice won’t do any good if it starts with the same seed value.
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.
my bad. I’m just used to C’s rand() that does nothing useful uless you seed it. Sorry about that.
*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.