Uniformly selects a random entry for the given position.

        :raises: :exc:`IndexError` if no entries are found.
354223
def choice(self, board: Union[chess.Board, int], *, minimum_weight: int = 1, exclude_moves: Container[chess.Move] = (), random=random) -> Entry:
        
        chosen_entry = None

        for i, entry in enumerate(self.find_all(board, minimum_weight=minimum_weight, exclude_moves=exclude_moves)):
            if chosen_entry is None or random.randint(0, i) == i:
                chosen_entry = entry

        if chosen_entry is None:
            raise IndexError()

        return chosen_entry
895219
def select_action(self, nb_actions, probs):
        
        action = np.random.choice(range(nb_actions), p=probs)
        return action
154577
def RWSelection(self, mating_pool_size):
		'''
		
		'''
		A = numpy.zeros(self.length)
		mating_pool = numpy.zeros(mating_pool_size)
	
		[F,S,P] = self.rankingEval()
		
		P_Sorted = numpy.zeros(self.length)
		for i in range(self.length):
			P_Sorted[i] = P[S[i]]
	
		for i in range(self.length):
			A[i] = P_Sorted[0:(i+1)].sum()

		i = 0
		j = 0
		while j < mating_pool_size:
			r = numpy.random.random()
			i = 0
			while A[i] < r:
				i += 1
			if numpy.shape(numpy.where(mating_pool==i))[1] == 0:
				mating_pool[j] =S[i]
				j += 1

		return mating_pool
710497
def pick_a_model_randomly(models: List[Any]) -> Any:
    
    try:
        return random.choice(models)
    except IndexError as e:
        raise ModelPickerException(cause=e)
1056404
def randomize(self, force = 0):
        
        if force or not self.frozen:
            self.weight = randomArray(self.size, self._maxRandom)
994930
def random_init_mapping(candidate_mapping):
    
    # if needed, a fixed seed could be passed here to generate same random (to help debugging)
    random.seed()
    matched_dict = {}
    result = []
    for c in candidate_mapping:
        candidates = list(c)
        if not candidates:
            # -1 indicates no possible mapping
            result.append(-1)
            continue
        found = False
        while candidates:
            # randomly generate an index in [0, length of candidates)
            rid = random.randint(0, len(candidates) - 1)
            candidate = candidates[rid]
            # check if it has already been matched
            if candidate in matched_dict:
                candidates.pop(rid)
            else:
                matched_dict[candidate] = 1
                result.append(candidate)
                found = True
                break
        if not found:
            result.append(-1)
    return result
968978
def pick(self):
        
        v = random.uniform(0, self.ub)
        d = self.dist
        c = self.vc - 1
        s = self.vc
        while True:
            s = s / 2
            if s == 0:
                break
            if v <= d[c][1]:
                c -= s
            else:
                c += s
                # we only need this logic when increasing c
                while len(d) <= c:
                    s = s / 2
                    c -= s
                    if s == 0:
                        break
        # we may have converged from the left, instead of the right
        if c == len(d) or v <= d[c][1]:
            c -= 1
        return d[c][0]
1281806
def random_combination_with_replacement(iterable, r):
    ""
    pool = tuple(iterable)
    n = len(pool)
    indices = sorted(random.randrange(n) for i in xrange(r))
    return tuple(pool[i] for i in indices)
365485
def select_random(engine, table_or_columns, limit=5):
    
    s = select(table_or_columns).order_by(func.random()).limit(limit)
    return engine.execute(s).fetchall()
764062
def query_random(**kwargs):
        '''
        
        '''

        if 'limit' in kwargs:
            limit = kwargs['limit']
        elif 'num' in kwargs:
            limit = kwargs['num']
        else:
            limit = 10

        kind = kwargs.get('kind', None)

        if kind:
            rand_recs = TabPost.select().where(
                (TabPost.kind == kind) &
                (TabPost.valid == 1)
            ).order_by(
                peewee.fn.Random()
            ).limit(limit)
        else:
            rand_recs = TabPost.select().where(
                TabPost.valid == 1
            ).order_by(
                peewee.fn.Random()
            ).limit(limit)
        return rand_recs
726455
def random(game):
    '''
    
    '''
    game.valid_moves = tuple(sorted(game.valid_moves, key=lambda _: rand.random()))
915767
def uniform(low, high, random_state):
    '''
    
    '''
    assert high > low, 'Upper bound must be larger than lower bound'
    return random_state.uniform(low, high)
168875
def selection(self):
        """"""
        sel = QtGui.QItemSelection()
        for index in self.selectedIndexes():
            sel.select(index, index)
        return sel
230737
def _random_cycle(adj, random_state):
    """"""

    # step through idx values in adj to pick a random one, random.choice does not work on dicts
    n = random_state.randint(len(adj))
    for idx, v in enumerate(adj):
        if idx == n:
            break
    start = v

    walk = [start]
    visited = {start: 0}

    while True:
        if len(walk) > 1:
            # as long as we don't step back one we won't have any repeated edges
            previous = walk[-2]
            neighbors = [u for u in adj[walk[-1]] if u != previous]
        else:
            neighbors = list(adj[walk[-1]])

        if not neighbors:
            # we've walked into a dead end
            return None

        # get a random neighbor
        u = random_state.choice(neighbors)
        if u in visited:
            # if we've seen this neighbour, then we have a cycle starting from it
            return walk[visited[u]:]
        else:
            # add to walk and keep moving
            walk.append(u)
            visited[u] = len(visited)
1184479
def get_random(self, n, l=None):
        
        random_f = Fasta()
        if l:
            ids = self.ids[:]
            random.shuffle(ids)
            i = 0
            while (i < n) and (len(ids) > 0):
                seq_id = ids.pop()
                if (len(self[seq_id]) >= l):
                    start = random.randint(0, len(self[seq_id]) - l)
                    random_f["random%s" % (i + 1)] = self[seq_id][start:start+l]
                    i += 1
            if len(random_f) != n:
                sys.stderr.write("Not enough sequences of required length")
                return
            else:
                return random_f

        else:
            choice = random.sample(self.ids, n)
            for i in range(n):
                random_f[choice[i]] = self[choice[i]]
        return random_f
1214399
def filter_by_rand(self, p:float, seed:int=None):
        ""
        if seed is not None: np.random.seed(seed)
        return self.filter_by_func(lambda o: rand_bool(p))
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;
    }