I'm wondering if, in the following example: using shuffle alone would be any more or less random than combining it with array_rand:
$arr = range(1, 100);
shuffle($arr);
echo 'shuffle: ';
var_dump($arr[0]);
echo 'shuffle + array_rand: ';
var_dump(array_rand($arr, 1));
The documentation for both shuffle and array_rand state that they use the same algorithm:
7.1.0 The internal randomization algorithm has been changed to use the » Mersenne Twister Random Number Generator instead of the libc rand function.
Now I don't recall where exactly, but I've fallen under the impression that attempting to randomize something multiple times can actually lead to it being less random. The best (and most concise) example I can think of is the Monty Hall problem.
So in the example above, would using array_rand in combination with shuffle actually make the result less random?
Aucun commentaire:
Enregistrer un commentaire