this is useful
git-svn-id: file:///home/shish/svn/shimmie2/trunk@899 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
8f252df282
commit
5e710361c4
1 changed files with 15 additions and 0 deletions
|
@ -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 *
|
* Event API *
|
||||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
Reference in a new issue