srand

FunctionParams changed in PHP 8.3

Seed the random number generator.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
Improved
PHP 8.2
Changed
PHP 8.3
Improved
PHP 8.4
PHP 8.5
PHP 8.6

srand Function synopsis

srand(?int $seed = null, int $mode = MT_RAND_MT19937): void

Parameters

$seed

OptionalType?intDefault valuenull

Fills the state with values generated with a linear congruential generator that was seeded with $seed interpreted as an unsigned 32 bit integer.

$mode

OptionalTypeintDefault valueMT_RAND_MT19937

$mode accepts one of the following constant values:

Return value

The srand function is a void function; it does not return any values.

Changes to the srand Function

PHP 8.3

  • Parameter type changed for parameter #1 ($seed): int to ?int
  • Parameter default value changed for position #1 ($seed): <default> to null
- srand(int $seed = <default>, int $mode = MT_RAND_MT19937): void
+ srand(?int $seed = null, int $mode = MT_RAND_MT19937): void

PHP 8.2

PHP 8.1

  • Parameter default value changed for position #1 ($seed): 0 to <default>
- srand(int $seed = 0, int $mode = MT_RAND_MT19937): void
+ srand(int $seed = <default>, int $mode = MT_RAND_MT19937): void

PHP 8.0

  • Return type added: void
  • Parameter type added for parameter #1 ($seed): int
  • Parameter default value added for position #1 ($seed): 0
  • Parameter type added for parameter #2 ($mode): int
  • Parameter default value added for position #2 ($mode): MT_RAND_MT19937
- srand($seed, $mode)
+ srand(int $seed = 0, int $mode = MT_RAND_MT19937): void

PHP 7.1

  • Optional parameter added - #2: $mode
- srand($seed)
+ srand($seed, $mode)

srand Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes