home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / php.exe / RandomDigits.php < prev    next >
Encoding:
PHP Script  |  2001-07-02  |  1.3 KB  |  40 lines

  1.     //**************************************
  2.     //     
  3.     // Name: RandomDigits
  4.     // Description:This function returns a r
  5.     //     andom string of a specified number of di
  6.     //     gits without leading zeros. For example,
  7.     //     if three digits are specified, the funct
  8.     //     ion will return a random three-digit num
  9.     //     ber from 100 to 999. by Michael A. Smith
  10.     //     
  11.     // By: PHP Code Exchange
  12.     //**************************************
  13.     //     
  14.     
  15.     <?php
  16.     /* RandomDigit 1.0 -- Copyright 1998 by Michael A. Smith -- msmith@dn.net
  17.     This function returns a random string of a specified number of digits
  18.     without leading zeros. For example, if three digits are specified, the
  19.     function will return a random three-digit number from 100 to 999. If you
  20.     specify an eight-digit string you will not get numbers with fewer than
  21.     eight digits, e.g. 376 or 6. */
  22.     function randomdigit($digits) { 
  23.     static $startseed = 0; 
  24.     if (!$startseed) {
  25.     $startseed = (double)microtime()*getrandmax(); 
  26.     srand($startseed);
  27.     }
  28.     $range = 8;
  29.     $start = 1;
  30.     $i = 1;
  31.     while ($i<$digits) {
  32.     $range = $range . 9;
  33.     $start = $start . 0;
  34.     $i++;
  35.     }
  36.     return (rand()%$range+$start); 
  37.     }
  38.     ?>
  39.  
  40.