About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Numbers - Random...

   Browse by title articles:
   What is hot:

Numbers - Random

Strings - Connecting

Strings - Pulling apart

if/elseif/else

switch/case

while/do while

Running a Program on a Remote Server Using SSH
See How To Troubleshoot Your Power Supply
Sitemaps and Hypertext Links: "Food" for Search Engine Robots
Comments
Prev articles123456 7 89101112Next articles



Numbers - Random


Computer & I'net articlesNumbers - Random

by David Stanley    



Creating a random number takes two commands called srand and rand. srand is a preparation command for rand. It helps rand create a truely random number. rand itself creates the random number.

<?php
srand ((double) microtime( )*1000000);
$random_number = rand( );
echo "$random_number";
?>

746666320

The value in the srand command is a number mixer, which is then passed into the actual rand command.

To make a random number within a specific range, you can add the number range in the rand command brackets. This example will find a number between 0 and 10:

<?php
srand ((double) microtime( )*1000000);
$random_number = rand(0,10);
echo "$random_number";
?>

10



-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.





Loan


  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com