
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
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
This example the random number generator is first initialized before employing rand() function−
<?php srand(5); echo "rand(1,100)=", rand(1,100); ?>
Output
This may produce following result −
rand(1,100)=12
Example
Following example uses current timestamp to initialize random number generator−
<?php srand(time()); echo "rand()=", rand(); ?>
Output
This may produce following result−
rand()=548287992
- Related Articles
- srand() function in PHP
- rand() and srand() in C
- rand() and srand() in C/C++
- PHP Function arguments
- PHP abs() Function
- PHP acos() Function
- PHP acosh() Function
- PHP asin() Function
- PHP asinh() Function
- PHP atan() Function
- PHP atan2() Function
- PHP atanh() Function
- PHP base_convert() Function
- PHP bindec() Function
- PHP ceil() Function

Advertisements