PHP mt_srand() Function

Definition and Usage

mt_srand() seeds the Mersenne Twister random number generator.

Syntax

mt_srand(seed)
Parameters Description
seed Required. Use seed to seed the random number generator.

Description

Starting from PHP 4.2.0 version,seed 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, it is no longer necessary to use srand() Or use mt_srand() function to seed the random number generator, which is now automatically completed.

Example

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

<?php
mt_srand(mktime());
echo(mt_rand());
?>

Output similar to:

1132656473