Are PHP random numbers predictable? if so, how difficult would it be to predict random numbers that are in a range of 1 to 32? and is there any way to make it unpredictable?
<?php
function rand_best($min, $max) {
$generated = array();
for ($i = 0; $i < 100; $i++) {
$generated[] = mt_rand($min, $max);
}
shuffle($generated);
$position = mt_rand(0, 99);
return $generated[$position];
}
?>
The mt_rand() function is a drop-in replacement for the older rand(). It uses a random number generator with known characteristics using the » Mersenne Twister, which will produce random numbers four times faster than what the average libc rand() provides.
The rand() function generates a random integer. Example tip: If you want a random integer between 10 and 100 (inclusive), use rand (10,100). Tip: As of PHP 7.1, the rand() function has been an alias of the mt_rand() function.
rand() or mt_rand() functions can be used to Generate 5 Digit Random Number in PHP.
rand() or mt_rand() functions can be used to Generate 4 Digit Random Number in PHP.
The discussion around how random random-functions in programming is, is ancient.
Take a look at this: http://en.wikipedia.org/wiki/Random_number_generation
Anyway. The random-functions are so good today that they are (what I would call) as near random as possible. There's no way to predict a result between 1,32 (or any other number for that sake). The deal is that the numbers are not truly random because a computer can not do such a operation.
I'd say the rand-functions is more than good enough unless you are writing something for Pentagon
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With