samedi 5 décembre 2015

pseudo random number genaration in PHP with srand and rand

I'm generating a sequence of pseudo random numbers with this code:

$seed = 1;
srand( $seed );
for($i=0; $i<10; $i++)
{
    echo rand(0,100) . "\n";
}
exit(0);

The following code outputs always (on my machine)

84
39
79
[....]
77
28
55

Can I rely on the fact that the output of the above code will be always the same?

If not, what could make it change?

For example may different versions of PHP give different results? Or PHP running on different OSes?




Aucun commentaire:

Enregistrer un commentaire