Subscribe to
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('');
    $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. 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