PHP srand() Function

Definition and Usage

The srand() function is used to seed the random number generaror. Seeding initializes the random number generator. Most random number generators need initial seeding. In PHP, use of srand() function is optional as it is done automatically.

This function doen't have any return value.

Syntax

srand ([ int $seed ] ) : void

Parameters

Sr.No Parameter & Description
1 seed
an integer to be used as seed. If not given, a random number is given

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
   srand(time());
   echo "rand()=", rand();
?>

Output

This may produce following result−

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

377 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements