Choose a list datanodes from the specified list. The best one is
the first one in the list.

If doRamdom is true, then
a random datanode is selected. Otherwise, a node that appears earlier
in the list has more probability of being selected
338927
public static <T extends DatanodeID> List<T> bestNode(T[] nodes, boolean doRandom) 
    throws IOException {
    TreeSet<T> deadNodes = new TreeSet<T>();
    T chosenNode = null;
    int failures = 0;
    Socket s = null;
    int index = -1;
    if (nodes == null || nodes.length == 0) {
      throw new IOException("No nodes contain this block");
    }
    while (s == null) {
      if (chosenNode == null) {
        do {
          if (doRandom) {
            index = rand.nextInt(nodes.length);
          } else {
            index++;
          }
          chosenNode = nodes[index];
        } while (deadNodes.contains(chosenNode));
      }
      chosenNode = nodes[index];

      //just ping to check whether the node is alive
      InetSocketAddress targetAddr = NetUtils.createSocketAddr(
          chosenNode.getHost() + ":" + chosenNode.getInfoPort());
        
      try {
        s = new Socket();
        s.connect(targetAddr, HdfsConstants.READ_TIMEOUT);
        s.setSoTimeout(HdfsConstants.READ_TIMEOUT);
      } catch (IOException e) {
        HttpServer.LOG.warn("Failed to connect to "+chosenNode.name, e);
        deadNodes.add(chosenNode);
        s.close();
        s = null;
        failures++;
      } finally {
        if (s!=null) {
          s.close();
        }
      }
      if (failures == nodes.length)
        throw new IOException("Could not reach the block containing the data. Please try again");
        
    }
    List<T> candidates;
    if (doRandom) {
      candidates = new ArrayList<T>(1);
      candidates.add(chosenNode);
    } else {
      candidates = new ArrayList<T>(nodes.length - index);
      for (int i=index; i<nodes.length - index; i++) {
        candidates.add(nodes[i]);
      }
    }
    return candidates;
  }
1084567
public static <T> T randomEle(List<T> list) {
		return randomEle(list, list.size());
	}
506655
def choose_one(things):
    """"""
    choice = SystemRandom().randint(0, len(things) - 1)
    return things[choice].strip()
215870
public static <T> T getRandomSelection(T... options) {
        if (options == null || options.length == 0) {
            if (tc.isDebugEnabled()) {
                Tr.debug(tc, "No options provided to random selection, returning null");
            }
            return null;
        }
        if (options.length == 1) {
            if (tc.isDebugEnabled()) {
                Tr.debug(tc, "Only one option provided to random selection, returning it: [" + options[0] + "]");
            }
            return options[0];
        }

        Random rand = new Random();
        Integer index = rand.nextInt(options.length);

        T entry = options[index];
        if (tc.isDebugEnabled()) {
            Tr.debug(tc, "Chose random selection: [" + ((entry == null) ? null : entry) + "]");
        }
        return entry;
    }
383686
def select(target, path, default=None, slient=True):
    
    def _(value, slient):
        if slient:
            return value
        else:
            raise KeyError("")
    default = partial(_, default, slient)
    names = path.split(".")
    node = target
    for name in names:
        if isinstance(node, dict):
            try:
                node = node[name]
            except:
                return default()
        elif isinstance(node, list) and name.isdigit():
            try:
                node = node[int(name)]
            except:
                return default()
        elif hasattr(node, name):
            node = getattr(node, name)
        else:
            return default()
    return node
614553
def SetSelected( self, node, point=None, propagate=True ):
        """"""
        if node == self.selectedNode:
            return
        self.selectedNode = node
        self.UpdateDrawing()
        if node:
            wx.PostEvent( self, SquareSelectionEvent( node=node, point=point, map=self ) )
729508
def copy_random_pointer_v1(head):
    
    dic = dict()
    m = n = head
    while m:
        dic[m] = RandomListNode(m.label)
        m = m.next
    while n:
        dic[n].next = dic.get(n.next)
        dic[n].random = dic.get(n.random)
        n = n.next
    return dic.get(head)
1212271
def _choice_from(self, key: str) -> str:
        """"""
        data = self._data[key]
        return self.random.choice(data)
1055937
def _choose_node(self, nodes=None):
        
        if not nodes:
            nodes = self.nodes

        # Prefer nodes which have gone a reasonable time without
        # errors
        def _error_rate(node):
            return node.error_rate.value()

        good = [n for n in nodes if _error_rate(n) < 0.1]

        if len(good) is 0:
            # Fall back to a minimally broken node
            return min(nodes, key=_error_rate)
        else:
            return random.choice(good)
1111890
def _select1(data, field, depth, output):
    
    for d in data:
        for i, f in enumerate(field[depth:]):
            d = d[f]
            if d == None:
                output.append(None)
                break
            elif is_list(d):
                _select1(d, field, i + 1, output)
                break
        else:
            output.append(d)
1165055
def select_node(**kw):
    
    with current_app.app_context():
        result = db.execute(text(fetch_query_string('select_node_from_id.sql')), **kw).fetchall()
        return result
1372022
public static <T> T randomEle(List<T> list, int limit) {
		return list.get(randomInt(limit));
	}
220675
private Set<Integer> perNodeRelease(final C thisNodeAddress, final C[] currentState, final int nodeCount, final int nodeRank) {
        final int numberIShouldHave = howManyShouldIHave(totalNumShards, nodeCount, minNodes, nodeRank);

        // destinationsAcquired reflects what we already have according to the currentState
        final List<Integer> destinationsAcquired = buildDestinationsAcquired(thisNodeAddress, currentState);

        final int numHad = destinationsAcquired.size();
        final Set<Integer> ret = new HashSet<>();
        if (destinationsAcquired.size() > numberIShouldHave) { // there's some to remove.
            final Random random = new Random();

            while (destinationsAcquired.size() > numberIShouldHave) {
                final int index = random.nextInt(destinationsAcquired.size());
                ret.add(destinationsAcquired.remove(index));
            }
        }

        if (LOGGER.isTraceEnabled() && ret.size() > 0)
            LOGGER.trace(thisNodeAddress.toString() + " removing shards " + ret + " because I have " +
                    numHad + " but shouldn't have more than " + numberIShouldHave + ".");

        return ret;
    }
356789
function (selection) {
      var rng = selection.getSel().getRangeAt(0);
      var startContainer = rng.startContainer;
      return startContainer.nodeType === 3 ? startContainer.parentNode : startContainer;
    }
286579
def list_nodes_select(conn=None, call=None):
    '''
    

    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes_select function must be called with -f or --function.'
        )
    return __utils__['cloud.list_nodes_select'](
        list_nodes(conn, 'function'), __opts__['query.selection'], call,
    )
459839
public static <T> T randomElementOf(final List<T> list) {
        if (list.isEmpty()) {
            return null;
        }
        return list.get(nextInt(0, list.size()));
    }
1042468
public static <T> T getRandomItem(List<T> list) {
		return list.get(rand.nextInt(list.size()));
	}