[SR-Users] LCR "weight" column question
Juha Heinanen
jh at tutpro.com
Sun Sep 26 08:03:16 CEST 2010
ricardo,
i studied the weight problem a bit more and came to the conclusion that
implementing a fair weighting algorithm would be too complicated.
below is a script that can be used to find weight values matching
desired probabilities for lcr gateways. i don't know if it would be
appropriate to include it in utils or scripts directory.
-- juha
#!/usr/bin/php
<?php
// This script can be used to find out actual probabilities
// that correspond to a list of LCR gateway weights.
if ($argc < 2) {
echo "Usage: lcr_weight_test.php <list of weights (integers 1-254)>\n";
exit;
}
$iters = 10000;
$rands = array();
for ($i = 1; $i <= $iters; $i++) {
$elem = array();
for ($j = 1; $j < $argc; $j++) {
$elem["$j"] = $argv[$j] * (rand() >> 8);
}
$rands[] = $elem;
}
$sorted = array();
foreach ($rands as $rand) {
asort($rand);
$sorted[] = $rand;
}
$counts = array();
for ($j = 1; $j < $argc; $j++) {
$counts["$j"] = 0;
}
foreach ($sorted as $rand) {
end($rand);
$counts[key($rand)]++;
}
for ($j = 1; $j < $argc; $j++) {
echo "weight " . $argv[$j] . " probability " . $counts["$j"]/$iters . "\n";
}
?>
More information about the sr-users
mailing list