dimanche 30 septembre 2018

PHP Rand function seems to be weighted

I am using the following code to test a function I have, but it seems like the rand function is generating weighted results:

$D22[] = rand(1,2)*10+rand(1,2);

Testing this is generating one of four numbers: 11,12,21,22. It should be running about 25% each, but 11 is actually only showing up about 5% of the time (only ran it 20 times).

What is causing this, and is there a better random function for PHP?

P.S.: I know this question is probably not valid for reasons. :)




Aucun commentaire:

Enregistrer un commentaire