samedi 8 décembre 2018

Why does rand seem more random than mt_rand when only doing (1, 2)?

I have some elements that I'm trying to randomize at 50% chance of output. Wrote a quick if statement like this.

$rand = mt_rand(1, 2);

if ( $rand == 1 ) {
echo "hello";
} else {
echo "goodbye";
}

In notice that when using mt_rand, "goodbye" is output many times in a row, whereas, if I just use "rand," it's a more equal distribution.

Is there something about mt_rand that makes it worse at handling a simple 1-2 randomization like this? Or is my dataset so small that these results are just anecdotal?




Aucun commentaire:

Enregistrer un commentaire