note 99857 added to function.rand
| From: | AlirezaEliaderani at osu1 dot php dot net | Date: | Fri, 10 Sep 2010 21:13:17 +0000 |
| Subject: | note 99857 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172459@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/99857
Del: integrated -- https://master.php.net/note/delete/99857/integrated
Del: useless -- https://master.php.net/note/delete/99857/useless
Del: bad code -- https://master.php.net/note/delete/99857/bad+code
Del: spam -- https://master.php.net/note/delete/99857/spam
Del: non-english -- https://master.php.net/note/delete/99857/non-english
Del: in docs -- https://master.php.net/note/delete/99857/in+docs
Del: other reasons-- https://master.php.net/note/delete/99857
Reject -- https://master.php.net/note/reject/99857
Search -- https://master.php.net/manage/user-notes.php