Get a random set of live neighbors
    (i.e. neighbors we've contacted before)
337176
def atlas_get_live_neighbors( remote_peer_hostport, peer_table=None, min_health=MIN_PEER_HEALTH, min_request_count=1 ):
    

    with AtlasPeerTableLocked(peer_table) as ptbl:
        alive_peers = []
        for peer_hostport in ptbl.keys():
            if peer_hostport == remote_peer_hostport:
                continue

            num_reqs = atlas_peer_get_request_count( peer_hostport, peer_table=ptbl )
            if num_reqs < min_request_count:
                continue

            health = atlas_peer_get_health( peer_hostport, peer_table=ptbl )
            if health < min_health:
                continue

            alive_peers.append( peer_hostport )

    random.shuffle(alive_peers)
    return alive_peers
1342244
private void useNextAddressAsNewContactSeedBroker() {
		if (++currentContactSeedBrokerIndex == seedBrokerAddresses.length) {
			currentContactSeedBrokerIndex = 0;
		}

		URL newContactUrl = NetUtils.getCorrectHostnamePort(seedBrokerAddresses[currentContactSeedBrokerIndex]);
		this.consumer = new SimpleConsumer(newContactUrl.getHost(), newContactUrl.getPort(), soTimeout, bufferSize, dummyClientId);
	}
1336390
function getNeighbor(owner, item, dataPropertyName) {
	const data = validateAttached(owner)
	return obtainTrueValue(item[data[dataPropertyName]])
}
644952
function Friends (client, opts) {
  var self = this
  if (!(self instanceof Friends)) return new Friends(client, opts)
  if (!opts) opts = {}

  self.client = client
}
673602
def get_lldp_neighbors_request(last_ifindex, rbridge_id):
        

        request_lldp = ET.Element(
            'get-lldp-neighbor-detail',
            xmlns="urn:brocade.com:mgmt:brocade-lldp-ext"
        )
        if rbridge_id is not None:
            rbridge_el = ET.SubElement(request_lldp, "rbridge-id")
            rbridge_el.text = rbridge_id
        elif last_ifindex != '':
            last_received_int = ET.SubElement(request_lldp,
                                              "last-rcvd-ifindex")
            last_received_int.text = last_ifindex

        return request_lldp
825675
private void addNeighborGroup(Collection<String> neighborGroups, Tile tile, int ox, int oy)
    {
        final Tile neighbor = map.getTile(tile.getInTileX() + ox, tile.getInTileY() + oy);
        if (neighbor != null)
        {
            final String neighborGroup = getNeighborGroup(tile, neighbor);
            if (neighborGroup != null)
            {
                neighborGroups.add(neighborGroup);
            }
        }
    }
315500
def set_neighbor_in_filter(neigh_ip_address, filters):
    """"""
    core = CORE_MANAGER.get_core_service()
    peer = core.peer_manager.get_by_addr(neigh_ip_address)
    peer.in_filters = filters
    return True
202745
def query_neighbors(self, nodes: List[Node]) -> List[Edge]:
        """"""
        return self.session.query(Edge).filter(self._edge_one_node(nodes)).all()
288768
def befriend(self, other_agent, force=False):
        '''
        
        '''
        if force or self['openness'] > random():
            self.env.add_edge(self, other_agent)
            self.info('Made some friend {}'.format(other_agent))
            return True
        return False
388554
async def random_connection(self):
        
        addr = choice(list(self._connections.keys()))
        return await self.env.connect(addr)
100401
private void calculateNearestNeighbors(int nn) {
        int n = this.dimension;
        if ((nn > 0) && (nn < n)) {
            nearestNeighbors = new int[n][nn];

            Neighbor[] neighbors = new Neighbor[n];
            for (int i = 0; i < n; i++) neighbors[i] = new Neighbor();

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    neighbors[j].id = j;
                    neighbors[j].distance = this.distances[i][j];
                }
                neighbors[i].distance = Integer.MAX_VALUE;
                Arrays.sort(neighbors);
                for (int j = 0; j < nn; j++) nearestNeighbors[i][j] = neighbors[j].id;
            }
        }
     }
612134
public Host getRandomHost(Set<Host> activeHosts) {
	Random random = new Random();

	List<Host> hostsUp = new ArrayList<Host>(CollectionUtils.filter(activeHosts, new Predicate<Host>() {

	    @Override
	    public boolean apply(Host x) {
		return x.isUp();
	    }
	}));

	return hostsUp.get(random.nextInt(hostsUp.size()));
    }
1243449
def neighbors(self, **kwargs):

        
        urn = "{urn:brocade.com:mgmt:brocade-lldp-ext}"

        result = []
        has_more = ''
        last_ifindex = ''
        rbridge_id = None
        if 'rbridge_id' in kwargs:
            rbridge_id = kwargs.pop('rbridge_id')
        while (has_more == '') or (has_more == 'true'):
            request_lldp = self.get_lldp_neighbors_request(last_ifindex,
                                                           rbridge_id)
            lldp_result = self._callback(request_lldp, 'get')
            has_more = lldp_result.find('%shas-more' % urn).text

            for item in lldp_result.findall('%slldp-neighbor-detail' % urn):
                local_int_name = item.find('%slocal-interface-name' % urn).text
                local_int_mac = item.find('%slocal-interface-mac' % urn).text
                last_ifindex = item.find(
                    '%slocal-interface-ifindex' % urn).text
                remote_int_name = item.find(
                    '%sremote-interface-name' % urn).text
                remote_int_mac = item.find('%sremote-interface-mac' % urn).text
                remote_chas_id = item.find('%sremote-chassis-id' % urn).text
                try:
                    remote_sys_name = item.find(
                        '%sremote-system-name' % urn).text
                except AttributeError:
                    remote_sys_name = ''
                try:
                    remote_sys_desc = item.find('%sremote-system-description' %
                                                urn).text
                except AttributeError:
                    remote_sys_desc = ''
                try:
                    remote_mgmt_addr = item.find(
                        '%sremote-management-address' %
                        urn).text
                except AttributeError:
                    remote_mgmt_addr = ''
                if 'Fo ' in local_int_name:
                    local_int_name = local_int_name.replace(
                        'Fo ',
                        'FortyGigabitEthernet '
                    )
                if 'Te ' in local_int_name:
                    local_int_name = local_int_name.replace(
                        'Te ',
                        'TenGigabitEthernet '
                    )

                item_results = {'local-int-name': local_int_name,
                                'local-int-mac': local_int_mac,
                                'remote-int-name': remote_int_name,
                                'remote-int-mac': remote_int_mac,
                                'remote-chassis-id': remote_chas_id,
                                'remote-system-name': remote_sys_name,
                                'remote-system-description': remote_sys_desc,
                                'remote-management-address': remote_mgmt_addr}
                result.append(item_results)

        return result
533157
def random_connection(self):
        ''''''
        # While at the moment there's no need for this to be a context manager
        # per se, I would like to use that interface since I anticipate
        # adding some wrapping around it at some point.
        yield random.choice(
            [conn for conn in self.connections() if conn.alive()])
158167
def _neighbors_graph(self, **params) -> Dict:
        
        response = self._get_response("graph/neighbors", format="json", **params)
        return response.json()
1155096
private static void shuffle(ArrayModifiableDBIDs ids, int ssize, int end, Random random) {
    ssize = ssize < end ? ssize : end; // Guard for choosing from tiny sets
    for(int i = 1; i < ssize; i++) {
      ids.swap(i - 1, i + random.nextInt(end - i));
    }
  }
44823
def get_neighbors( self, peer_hostport, con=None, path=None, peer_table=None ):
        
        if path is None:
            path = self.atlasdb_path

        if self.neighbors_timeout is None:
            self.neighbors_timeout = atlas_neighbors_timeout()
 
        peer_hostport = self.canonical_peer( peer_hostport )

        neighbors = None
        if peer_hostport == self.my_hostport:
            neighbors = atlas_get_live_neighbors( None, peer_table=peer_table ) 
        else:
            neighbors = atlas_peer_get_neighbors( self.my_hostport, peer_hostport, timeout=self.neighbors_timeout, peer_table=peer_table, path=path, con=con )

        if neighbors is not None:
            log.debug("%s: neighbors of %s are (%s): %s" % (self.my_hostport, peer_hostport, len(neighbors), ",".join(neighbors)))
        else:
            log.error("%s: failed to ask %s for neighbors" % (self.my_hostport, peer_hostport))

        return neighbors