I want to produce a natural number (a positive integer between 0 and x) by using lcg_value(). This is what I can see from the actual source code for the function:
/*
* combinedLCG() returns a pseudo random number in the range of (0, 1).
* The function combines two CGs with periods of
* 2^31 - 85 and 2^31 - 249. The period of this function
* is equal to the product of both primes.
*/
Now, how would I turn that float into a natural number so that I do not lose information/entropy. Currently I just do it like this:
$number = pow(2,31) * lcg_value();
However, I have a feeling in my gut that it’s not perfect. How about 2^62? Or perhaps 2^31-334? Or 2^62-334? I don’t know.
either type float or int are bounded by platform
to maintain highest precision of float, u can refer http://www.php.net/manual/en/function.bcmul.php