In PHP, how do I generate a big pseudo-random number?
This will give you more zeros in your giant random number and you can also specify the length of the giant random number (can your giant random number start with a 0? if not, that can also be easily implemented)
<?php
$randNumberLength = 1000; // length of your giant random number
$randNumber = NULL;
for ($i = 0; $i < $randNumberLength; $i++) {
$randNumber .= rand(0, 9); // add random number to growing giant random number
}
echo $randNumber;
?>
Good luck!
What you really need to know is the relative gap; if it's small then you can generate a number from 0 to the maximum gap then add the minimum to that.
Try the following:
function BigRandomNumber($min, $max) {
$difference = bcadd(bcsub($max,$min),1);
$rand_percent = bcdiv(mt_rand(), mt_getrandmax(), 8); // 0 - 1.0
return bcadd($min, bcmul($difference, $rand_percent, 8), 0);
}
The math is as following: multiply the difference between the minimum and maximum by a random percentage, and add to the minimum (with rounding to an int).