
- 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
rand() function in PHP
The rand() function gets a random number. You can also set a range to get random number from that particular range.
Syntax
rand(); or rand(min_range,max_range);
Parameters
min_range − Default is 0. This is the lowest number to be Returned.
max_range − This is the highest number to be Returned.
Return
The rand() function Returns a random integer between min_range and max_range.
Example
<?php echo(rand() . "<br>"); echo(rand() . "<br>"); echo(rand() . "<br>"); echo(rand() . "<br>"); echo(rand() . "<br>"); echo(rand()); ?>
Output
1581227270<br>1094001227<br>306337052<br>151211887<br>7894804<br>115835633
Example
Let us see another example −
<?php echo(rand(2, 5) . "<br>"); echo(rand(90, 190)); ?>
Output
4<br>114
- Related Articles
- PHP rand() Function
- rand() and srand() in C
- rand() and srand() in C/C++
- filter_has_var() function in PHP
- filter_id() function in PHP
- filter_input() function in PHP
- filter_input_array() function in PHP
- filter_list() function in PHP
- filter_var_array() function in PHP
- filter_var() function in PHP
- constant() function in PHP
- define() function in PHP
- defined() function in PHP
- die() function in PHP
- eval() function in PHP

Advertisements