PHP mt_srand() Function

Definition and Usage

Prefix 'mt' in function's name stands for Mersenne Twister. The mt_srand() function is used to seed the Mersenne Twister random number generaror. Seeding initializes the random number generator. Most random number generators need initial seeding. In PHP, use of mt_srand() function is optional as it is done automatically.

This function doen't have any return value.

Syntax

mt_srand ([ int $seed [, int $mode = MT_RAND_MT19937 ]] ) : void

Parameters

Sr.No Parameter & Description
1 seed
an integer to be used as seed. If not given, a random number is given
2 mode
Use one of the following constants to specify mode of implementation
MT_RAND_MT19937 uses fixed Mersenne Twister implementation
MT_RAND_PHP uses default implementation

Return Values

This function doesn't return any value.

PHP Version

This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.

Example

<?php
   mt_srand(time());
   echo "mt_rand()=", mt_rand();
?>

Output

This may produce following result−

mt_rand()=548287992
Updated on: 2026-03-11T23:22:53+05:30

472 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements