1. Home
  2. Computing & Technology
  3. PHP / MySQL

Rand () PHP Function

By Angela Bradley, About.com

Definition: The rand () function is used to generate a random number in PHP. It can also be used to generate a random number within a specific range (for example a number between 10 and 30.) On a some platforms, Windows for example, if unspecified the largest number that will be generated is 32768, however you can set a specific range to include higher numbers.
Examples:
<?php
print rand() . "<br>";
//generates and prints a random number
print rand(10, 30);
//generates and prints a random number between 10 and 30 (10 and 30 ARE included)
print rand(1, 1000000);
//generates and prints a random number between on and one million
?>
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. Generating Random Number - Random Number Generator - Random Number PHP

©2009 About.com, a part of The New York Times Company.

All rights reserved.