PHP function of the day: srand()

For day 18 of 21 in the “PHP Function of the day” series, I’m going to look at srand(). The function lets you specify the seed for rand().  In modern versions of PHP, rand() is seeded automatically and there is no real reason to do this.  So, why the explanation?  YOLO? 🙂

Let’s take a look.

<?php

srand(mktime());

echo(rand());

?>

 

See the output

 

There are three more posts left in this series.  Starting next week, I’m going back to the cadence that I was using in April.  Later in the year, I might try this daily post thing again.  Have a question, comment, etc?  Feel free to drop a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *