PHP srand() Function

❮ PHP Math Reference

Example

Seed the random number generator:

<?php
srand(mktime());
echo(rand());
?>
Try it Yourself »

Definition and Usage

The srand() function seeds the random number generator (rand()).

Tip: From PHP 4.2.0, the random number generator is seeded automatically and there is no need to use this function.


Syntax

srand(seed);

Parameter Values

Parameter Description
seed Optional. Specifies the seed value

Technical Details

Return Value: None
Return Type: -
PHP Version: 4+
PHP Changelog: PHP 7.1.0: srand() has been an alias of mt_srand().
PHP 4.2.0: Random number generator is now seeded automatically.

❮ PHP Math Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.