PHP srand() Function

Definition and Usage

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

Syntax

srand(seed)
Parameters Description
seed Optional. Use seed to seed the random number generator seed.

Description

Starting from PHP 4.2.0 versionseed Parameters become optional, when this item is empty, it will be set to the current time.

Tips and Comments

Note:Since PHP 4.2.0, srand() or mt_srand() The function seeds the random number generator, now it is automatically completed.

Example

In this example, we will seed the random number generator:

<?php
srand(mktime());
echo(rand());
?>

Output:

23054