BBS水木清华站∶精华区

发信人: thinkin (强强), 信区: Linux        
标  题: RandomDigits  
发信站: BBS 水木清华站 (Thu Feb 17 11:06:50 2000) 
 
<?php 
/* RandomDigit 1.0 -- Copyright 1998 by Michael A. Smith -- msmith@dn.net 
This function returns a random string of a specified number of digits 
without leading zeros. For example, if three digits are specified, the 
function will return a random three-digit number from 100 to 999. If you 
specify an eight-digit string you will not get numbers with fewer than 
eight digits, e.g. 376 or 6. */ 
function randomdigit($digits) { 
   static $startseed = 0; 
   if (!$startseed) { 
      $startseed = (double)microtime()*getrandmax(); 
      srand($startseed); 
   } 
   $range = 8; 
   $start = 1; 
   $i = 1; 
   while ($i<$digits) { 
      $range = $range . 9; 
      $start = $start . 0; 
      $i++; 
   } 
   return (rand()%$range+$start); 

?> 
-- 
 
人生到处知何似? 
    应似飞鸿踏雪泥。 
        泥上偶然留指爪, 
            鸿飞那复计东西! 
        
 
※ 来源:·BBS 水木清华站 smth.org·[FROM: 162.105.37.191] 

BBS水木清华站∶精华区