In PHP, how do I generate a big pseudo-random number?

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).

How to ceil, floor and round bcmath numbers?

After a night lost trying to solve this problem I believe I’ve found a rather simple solution, here it is: function bcceil($number) { if (strpos($number, ‘.’) !== false) { if (preg_match(“~\.[0]+$~”, $number)) { return bcround($number, 0); } if ($number[0] != ‘-‘) { return bcadd($number, 1, 0); } return bcsub($number, 0, 0); } return $number; } … Read more