PHP rand() Function

❮ PHP Math Reference

Example

Generate random numbers:

<?php
echo(rand() . "<br>");
echo(rand() . "<br>");
echo(rand(10,100));
?>
Try it Yourself »

Definition and Usage

The rand() function generates a random integer.

Example tip: If you want a random integer between 10 and 100 (inclusive), use rand (10,100).

Tip: As of PHP 7.1, the rand() function has been an alias of the mt_rand() function.

Syntax

rand();

or

rand(min,max);

Parameter Values

Parameter Description
min Optional. Specifies the lowest number to return. Default is 0
max Optional. Specifies the highest number to return. Default is getrandmax()

Technical Details

Return Value: A random integer between min (or 0) and max (or getrandmax() inclusive)
Return Type: Integer
PHP Version: 4+
PHP Changelog: PHP 7.1: The rand() function is an alias of mt_rand().
PHP 4.2.0: The random number generator is seeded automatically.

❮ PHP Math Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.