2.2 too
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.2@900 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
5f473aff6d
commit
763538c096
@ -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 *
|
||||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user