this is useful

git-svn-id: file:///home/shish/svn/shimmie2/trunk@899 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-06-14 18:45:00 +00:00
parent 8f252df282
commit 5e710361c4

View file

@ -455,6 +455,21 @@ function sanitise_environment() {
}
}
function weighted_random($weights) {
$total = 0;
foreach($weights as $k => $w) {
$total += $w;
}
$r = mt_rand(0, $total);
foreach($weights as $k => $w) {
$r -= $w;
if($r <= 0) {
return $k;
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Event API *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */