Jump to content

Generate a VERY large random number


Mgccl

Recommended Posts

function generate_password($length= {
$password = "";
$possible = "0123456789";
$i = 0;
while ( $i < $length ) {
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
$password .= $char;
$i++;
}
return $password;
}
$password = generate_password($length=;//8 can be optimzed to the no. of digits you want.

As long as php can run, i guess however many digits you wish, it can be generated, but processing it such as division or multiplication, im not sure.

btw. basically used the random pass. just limited the string to numeric.

Ted

;)

Thx guys.

Here is the script I have made, kinda fast :)

function bcrand($min, $max){//input STRING!
$top = bcsub($max,$min);
$rand = bcadd($top, 1);
$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);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.