1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Rand () PHP Function

By

Businesswoman working in the office
Zhang Bo/E+/Getty Images
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
 ?>
  1. About.com
  2. Technology
  3. PHP / MySQL
  4. PHP Functions
  5. Rand () PHP Function - Definition and Examples

©2014 About.com. All rights reserved.