Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   CD Forum Support (http://www.chiefdelphi.com/forums/forumdisplay.php?f=8)
-   -   how random are the spotlights? (http://www.chiefdelphi.com/forums/showthread.php?t=16319)

Joe Ross 01-11-2003 01:55 PM

how random are the spotlights?
 
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

Code:

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]

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? 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().
Quote:

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

Quote:

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.


All times are GMT -5. The time now is 02:36 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi