vendredi 13 octobre 2017

How to improve array_rand() function with PHP?

I use the array_rand PHP function with an array. I use it with a data fixture function wich load a set of data in a loop like this:

$random_values = array();
for ($i = 0; $i < 20; $i++) {
    $random_values[] = array_rand(["1","2","3","4","5"]);
}

My result is quite always "1" in the $random_values array, the native PHP function seems not really random, Is there another stuff to do to improve the randomization of my algorithm ?

Notice I already know there is an official documentation here, http://ift.tt/2ykSo1I.




Aucun commentaire:

Enregistrer un commentaire