Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 1
There are 1 users currently browsing forums.
Reply
  #1  
Old 02-05-2007
College Student
 
Join Date: Jan 2007
Posts: 210
Rep Power: 4
Mgccl is on a distinguished road
Generate very large random number in non *nix server

Works great and fast. I can't find any way to optimize it.
PHP Code:
function bcrand($min$max){
    if(
bccomp($max,$min)!=1){
        return 
0;
    }
    
$top bcsub($max,$min);
    
$rand bcadd($top1);
    
$length strlen($top);
    while(
bccomp($rand,$top)==1){
        unset(
$rand_part);
        
$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;
        }
    }
    return 
bcadd($rand,$min,0);

Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shared Hosting VS Dedicated Server starsearcher Web Hosting Help 5 06-08-2006 07:44 AM