note 97974 added to function.mt-rand
| From: | kexianbin at diyism dot com | Date: | Wed, 19 May 2010 05:38:27 +0000 |
| Subject: | note 97974 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169388@lists.php.net to get a copy of this message | ||
function weight_rand($weights)
{$rnd=mt_rand(1, array_sum($weights));
$max=0;
foreach ($weights as $k=>$v)
{$max+=$v;
if (1<=$rnd && $rnd<=$max)
{return $k;
}
}
}
echo weight_rand(array('a'=>30, 'b'=>70));
----
Server IP: 69.147.83.197
Probable Submitter: 192.251.226.206
----
Manual Page -- http://www.php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/97974
Del: integrated -- https://master.php.net/note/delete/97974/integrated
Del: useless -- https://master.php.net/note/delete/97974/useless
Del: bad code -- https://master.php.net/note/delete/97974/bad+code
Del: spam -- https://master.php.net/note/delete/97974/spam
Del: non-english -- https://master.php.net/note/delete/97974/non-english
Del: in docs -- https://master.php.net/note/delete/97974/in+docs
Del: other reasons-- https://master.php.net/note/delete/97974
Reject -- https://master.php.net/note/reject/97974
Search -- https://master.php.net/manage/user-notes.php