I\'m looking for a way to generate a big random number with PHP, something like:
mt_rand($lower, $upper);
The closer I\'ve
This might work for you. (I am not sure why you need it, so it might not be the best way to do it, but it should fit your requirements):
$tempMax)
{
$lastDigitMin = substr($tempMin, -1);
$lastDigitMax = substr($tempMax, -1);
$tempRand = $rand . @mt_rand($lastDigitMin, $lastDigitMax);
}
/* Check if $tempRand is equal to the min or to the max value.
If it is not equal, then we know it will stay in range */
if ($tempRand > $tempMin && $tempRand < $tempMax)
{
$b_inRange = true;
}
}
else
{
$tempRand = $rand . $randDigit;
}
$rand = $tempRand;
}
return $rand;
}
I tried a couple times and it looks like it works OK. Optimize if needed. The idea is to start by figuring out a random length for your random number that would put it in the acceptable range. Then generate random digits one by one up to that length by concatenating. If it is not in range, generate a new random digit in range and concatenate.
I use the fact that PHP will convert a string to a number to take advantage of the string functions. Of course this generates a warning for mt_rand, but as we use only numbers, it should be safe to suppress it.
Now, I have to say that I am quite curious as to why you need this in the first place.