mercredi 29 novembre 2017

Difference between rand(min, max) and rand()/getrandmax()

I saw some people trying to generate random numbers between a range of two numbers using just:

$random_num = rand($min, $max);

while I see other people using something more complicated like "Dividing rand() by the maximum random number, multiply it by the range and add the starting number:

$random_num = $min + ($max - $min) * (rand()/getrandmax());

where $min is the starting number and $max is the ending number.

I would like to know what is the difference between these two ways, is one better than the other, if so why?

Thanks




Aucun commentaire:

Enregistrer un commentaire