Subscribe to
Posts
Comments
NSLog(); Header Image

Random Quotes

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.

4 Responses to "Random Quotes"

  1. uhm, why are you seeding the random number generator each time? It's a Bad Thing (and worthless)

  2. 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.

  3. A belated thank you for posting this! It's good to have some options.

  4. Knowledge Sharing

    One of the cool benefits of blogging is sharing knowledge with other bloggers. Of course, there are community blogs like


Trackback URI | Comments RSS

Leave a Reply

Please abide by the comment policy. Valid HTML includes: <blockquote><p>, <em>, <strong>, <ul>, <ol>, and <a href>. Please use the "Quote Me" functionality to quote comments.