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 Parameters become optional, and when this item is empty, it will be set to the current time.

Tips and Comments

Note:From PHP 4.2.0 onwards, it is no longer necessary to use srand() Or seed the random number generator with mt_srand() function, 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