PHP mt_srand() Function

Definition and Usage

mt_srand() seeds the Mersenne Twister random number generator.

Syntax

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

Description

Starting from PHP 4.2.0 version,seed The parameter becomes optional. When this item is empty, it will be set to the current time.

Tips and Comments

Note:Since PHP 4.2.0, there is no longer a need to use srand() Or mt_srand() function to seed the random number generator, now it is automatically completed.

Example

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

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

Output like:

1132656473