Jabber-Lite
view release on metacpan or search on metacpan
lib/Jabber/Lite.pm view on Meta::CPAN
# Work out a position for this weight, between
# 0 and $wghtcnt (inclusive).
my $wghtpos = abs( int( rand( $wghtcnt + 1 ) + ( $wghthigh - $wghtnum ) ) );
my $trycnt = 0;
while( defined( $weights{"$wghtpos"} ) && $trycnt < $wghtcnt ){
$wghtpos = abs( int( rand( $wghtcnt + 1 ) + ( $wghthigh - $wghtnum ) ) );
$trycnt++;
}
# Did the loop exit due to success, or because
# of too many iterations?
if( defined( $weights{"$wghtpos"} ) ){
# Count up until we find one.
$wghtpos = 0;
while( defined( $weights{"$wghtpos"} ) ){
$wghtpos++;
}
}
# Save the port and host.
$weights{"$wghtpos"} = "$port $host";
( run in 1.358 second using v1.01-cache-2.11-cpan-71847e10f99 )