note 99859 added to function.rand

From: Date: Fri, 10 Sep 2010 21:18:24 +0000
Subject: note 99859 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-172461@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 69.163.177.154 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/99859 Del: integrated -- https://master.php.net/note/delete/99859/integrated Del: useless -- https://master.php.net/note/delete/99859/useless Del: bad code -- https://master.php.net/note/delete/99859/bad+code Del: spam -- https://master.php.net/note/delete/99859/spam Del: non-english -- https://master.php.net/note/delete/99859/non-english Del: in docs -- https://master.php.net/note/delete/99859/in+docs Del: other reasons-- https://master.php.net/note/delete/99859 Reject -- https://master.php.net/note/reject/99859 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172461) next »