Random Quotes
Posted April 17th, 2003 @ 08:29pm by Erik J. Barzeski
Some guy named Gabe Anderson asked me how I do the random quotes you see to the left. Quite simple, really!
<? $lines = file('http://nslog.com/quotes.txt'); $count = count($lines); $linenumber = rand()%$count; echo $lines[$linenumber]; ?>
May not be the most efficient means of doing this, but it certainly works.
Posted 18 Apr 2003 at 2:54am #
uhm, why are you seeding the random number generator each time? It's a Bad Thing (and worthless)
Posted 18 Apr 2003 at 8:42am #
PHP.net says this: "In older versions of PHP, you had to seed the random number generator before use with srand(). Since 4.2.0 this is no longer necessary."
This server ain't running 4.2.0, so I'm not sure what's going on, but it works without srand for now, so fine.
Posted 24 Apr 2003 at 11:41am #
A belated thank you for posting this! It's good to have some options.
Posted 24 Apr 2003 at 11:54am #
Knowledge Sharing
One of the cool benefits of blogging is sharing knowledge with other bloggers. Of course, there are community blogs like