mardi 14 janvier 2020

Does PHP's rand function give an even distribution?

I am writing a simple dice roller in PHP. I don't care about the rolls being cryptographically secure, but it is important that they have two features:

  1. Each roll is effectively independent (i.e. if I rolled a 6 last roll, I still have a 1/6 chance of rolling a 6 next roll).
  2. The results are evenly distributed for the range provided. (i.e. rand (1,6) will give me on average a 1/6 change of getting each value).

Des PHP rand fulfill these two requirements? If not, which PHP function can I use that will provide me with this contract?




Aucun commentaire:

Enregistrer un commentaire