public function selectConnection(array $connections)
    {
        $weighted = [];

        foreach ($connections as $connection) {
            foreach (range(0, $connection['weight']) as $i) {
                $weighted[] = $connection;
            }
        }

        $index = mt_rand(0, count($weighted) - 1);

        return $weighted[$index];
    }
public function selectConnection(array $connections)
    {
        $weighted = [];

        foreach ($connections as $connection) {
            foreach (range(0, $connection['weight']) as $i) {
                $weighted[] = $connection;
            }
        }

        $index = mt_rand(0, count($weighted) - 1);

        return $weighted[$index];
    }
public function selectConnection ( array $ connections ) { $ weighted = [ ] ; foreach ( $ connections as $ connection ) { foreach ( range ( 0 , $ connection [ 'weight' ] ) as $ i ) { $ weighted [ ] = $ connection ; } } $ index = mt_rand ( 0 , count ( $ weighted ) - 1 ) ; return $ weighted [ $ index ] ; }
Select connection randomly accounting for weight.

@param array $connections

@return OptionsBag
Select connection randomly accounting for weight .