// Pick returns a NumberGenerator from a pool of NumberGenerators
487125
func (r *Pool) Pick() NumberGenerator {
	// use round robin with fast modulus of pow2 numbers
	selection := atomic.AddUint64(&r.counter, 1) & (r.size - 1)
	return r.sources[selection]
}
1085928
func (v *PVector) Peek() interface{} {
	if v.cnt > 0 {
		return v.Nth(v.cnt - 1)
	}
	return nil
}
841865
func (m *JobExecutor) WalkSelect(p *plan.Select) (Task, error) {
	root := m.NewTask(p)
	return root, m.WalkChildren(p, root)
}
611259
func Generate(length, numDigits, numSymbols int, noUpper, allowRepeat bool) (string, error) {
	gen, err := NewGenerator(nil)
	if err != nil {
		return "", err
	}

	return gen.Generate(length, numDigits, numSymbols, noUpper, allowRepeat)
}
941900
func pickRandom(cur_person Person) (*Person, error) {
	list := rand.Perm(len(avail_pool))
	for i := range list {
		var random Person = avail_pool[i]
		if isValid(cur_person, random, true) {
			avail_pool = append(avail_pool[:i], avail_pool[i+1:]...)
			return &random, nil
		}
	}

	return nil, fmt.Errorf("couldn't find an available participant")
}
1061911
func (b *baseBalancer) regeneratePicker() {
	if b.state == connectivity.TransientFailure {
		b.picker = NewErrPicker(balancer.ErrTransientFailure)
		return
	}
	readySCs := make(map[resolver.Address]balancer.SubConn)

	// Filter out all ready SCs from full subConn map.
	for addr, sc := range b.subConns {
		if st, ok := b.scStates[sc]; ok && st == connectivity.Ready {
			readySCs[addr] = sc
		}
	}
	b.picker = b.pickerBuilder.Build(readySCs)
}
213413
func (r *Random) Select(pool HostPool) *UpstreamHost {
	// instead of just generating a random index
	// this is done to prevent selecting a down host
	var randHost *UpstreamHost
	count := 0
	for _, host := range pool {
		if host.Down() {
			continue
		}
		count++
		if count == 1 {
			randHost = host
		} else {
			r := rand.Int() % count
			if r == (count - 1) {
				randHost = host
			}
		}
	}
	return randHost
}
689150
func (b *Base) PickFunc(converter ValueConverter, keys ...string) Serializer {
	return b.PickFuncIf(alwaysTrue, converter, keys...)
}
850731
func (t *Array) Select(pos int) Type {
	if len(t.static) > pos {
		return t.static[pos]
	}
	if t.dynamic != nil {
		return t.dynamic
	}
	return nil
}
134455
func (l *List) Select(i int) {
	l.SetSelected(i)
	if l.onSelectionChanged != nil {
		l.onSelectionChanged(l)
	}
}
426375
func pickNoun(n int, singular, plural string) string {
	if n == 1 {
		return singular
	}
	return plural
}
1040178
func (b *AnnealingEpsilonGreedy) Select() int {
	if rand.Float64() > b.Epsilon() {
		// Select the maximal value from values.
		max := -1.0
		idx := -1

		// Find the index of the maximal value.
		for i, val := range b.values {
			if val > max {
				max = val
				idx = i
			}
		}

		return idx
	}

	// Otherwise return any of the values
	return rand.Intn(len(b.values))
}
1256371
func (l *StringLexer) Grab(t ItemType) Item {
	// special case
	str := l.BufferString()
	line := l.line
	if len(str) > 0 && str[0] == '\n' {
		line--
	}
	return NewItem(t, l.start, line, str)
}
1102404
func PickN(population []interface{}, n int) (
	picked []interface{}, remaining []interface{}, err error) {

	total := len(population)
	idxs, err := SampleInts(total, n)
	if err != nil {
		return
	}
	sort.Ints(idxs)

	picked, remaining = []interface{}{}, []interface{}{}
	for x, elem := range population {
		if len(idxs) > 0 && x == idxs[0] {
			picked = append(picked, elem)
			idxs = idxs[1:]
		} else {
			remaining = append(remaining, elem)
		}
	}

	return
}
1020791
func (s *SelectQuery) Select(cols ...string) *SelectQuery {
	s.selects = cols
	return s
}
72485
func (bp *pickerWrapper) updatePicker(p balancer.Picker) {
	bp.mu.Lock()
	if bp.done {
		bp.mu.Unlock()
		return
	}
	bp.picker = p
	// bp.blockingCh should never be nil.
	close(bp.blockingCh)
	bp.blockingCh = make(chan struct{})
	bp.mu.Unlock()
}
669454
func (q *querier) Select(matchers ...*labels.Matcher) (storage.SeriesSet, error) {
	minFrom := uint32(math.MaxUint32)
	var maxTo uint32
	var target string
	var reqs []models.Req

	expressions := []string{}
	for _, matcher := range matchers {
		if matcher.Name == model.MetricNameLabel {
			matcher.Name = "name"
		}
		if matcher.Type == labels.MatchNotRegexp {
			expressions = append(expressions, fmt.Sprintf("%s!=~%s", matcher.Name, matcher.Value))
		} else {
			expressions = append(expressions, fmt.Sprintf("%s%s%s", matcher.Name, matcher.Type, matcher.Value))
		}
	}

	series, err := q.clusterFindByTag(q.ctx, q.OrgID, expressions, 0, maxSeriesPerReq)
	if err != nil {
		return nil, err
	}

	if q.metadataOnly {
		return BuildMetadataSeriesSet(series)
	}

	minFrom = util.Min(minFrom, q.from)
	maxTo = util.Max(maxTo, q.to)
	for _, s := range series {
		for _, metric := range s.Series {
			for _, archive := range metric.Defs {
				consReq := consolidation.None
				fn := mdata.Aggregations.Get(archive.AggId).AggregationMethod[0]
				cons := consolidation.Consolidator(fn)

				newReq := models.NewReq(archive.Id, archive.NameWithTags(), target, q.from, q.to, math.MaxUint32, uint32(archive.Interval), cons, consReq, s.Node, archive.SchemaId, archive.AggId)
				reqs = append(reqs, newReq)
			}
		}
	}

	select {
	case <-q.ctx.Done():
		//request canceled
		return nil, fmt.Errorf("request canceled")
	default:
	}

	reqRenderSeriesCount.Value(len(reqs))
	if len(reqs) == 0 {
		return nil, fmt.Errorf("no series found")
	}

	// note: if 1 series has a movingAvg that requires a long time range extension, it may push other reqs into another archive. can be optimized later
	reqs, _, _, err = alignRequests(uint32(time.Now().Unix()), minFrom, maxTo, reqs)
	if err != nil {
		log.Errorf("HTTP Render alignReq error: %s", err.Error())
		return nil, err
	}

	out, err := q.getTargets(q.ctx, reqs)
	if err != nil {
		log.Errorf("HTTP Render %s", err.Error())
		return nil, err
	}

	return SeriesToSeriesSet(out)
}