note 99857 deleted from function.rand by danbrown

From: Date: Fri, 10 Sep 2010 21:23:56 +0000
Subject: note 99857 deleted from function.rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172464@lists.php.net to get a copy of this message
Note Submitter: Alireza Eliaderani ---- random integers with normal distribution, it's not scientifically approved, but worked for me. <?php /* * @param number $mean, desired average * @param number $sd, number of items in array * @return array */ function distribute($mean,$sd){ $result = array(); $total_mean = intval($mean*$sd); while($sd>1){ $allowed_max = $total_mean - $sd - 1; $allowed_min = intval($total_mean/$sd); $random = mt_rand($allowed_min , min(5,$allowed_max)); $result[]=$random; $sd--; $total_mean-=$random; } $result[] = $total_mean; return $result; } ?>

« previous php.notes (#172464) next »