A Function Returns Large Random Numbers | ||
| ||
| made because the rand() and mt_rand() function can not accept numbers larger than 2^31 or 2^63,depend on your processor and complier. <?php function bcrand($min,$max){ bcscale(0); if(bccomp($max,$min)!=1){ return 0; } $top = bcsub($max,$min); $rand = bcadd($top,1); $length = strlen($top); $n = 0; while(9*$n <= $length){ if($length - 9*$n >= 9){ $rand_part[] = rand(0,999999999); }else{ $j = 0; $foo = ''; while($j < $length-9*$n){ $foo .= '9'; $j; } $foo = 0; $rand_part[] = rand(0,$foo); } $n; } $i = 0; $rand =''; $count = count($rand_part); while($i < $count){ $rand .= $rand_part[$i]; $i; } while(bccomp($rand,$top)==1){ $rand = substr($rand,1,strlen($rand)).rand(0,9); } return bcadd($rand,$min); } ?> | ||
| | ||
| |