PHP mt_srand() Function

❮ PHP Math Reference

Example

Seed the random number generator:

<?php
mt_srand(mktime());
echo(mt_rand());
?>
Try it Yourself »

Definition and Usage

The mt_srand() function seeds the Mersenne Twister random number generator.


Syntax

mt_srand(seed, mode);

Parameter Values

Parameter Description
seed Optional. Specifies the seed value
mode Optional. Specifies the algorithm to use. Can be one of the following constants:
  • MT_RAND_MT19937 - uses the fixed, correct Mersenne Twister implementation (which is used from PHP 7.1)
  • MT_RAND_PHP - uses the incorrect Mersenne Twister implementation (which was used up to PHP 7.1)

Technical Details

Return Value: None
Return Type: -
PHP Version: 4+
PHP Changelog: PHP 4.2.0: Random number generator is now seeded automatically

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