// LazyShuffle randomizes the row order without re-ordering the rows
// via an InstancesView.
184157
func LazyShuffle(from FixedDataGrid) FixedDataGrid {
	_, rows := from.Size()
	rowMap := make(map[int]int)
	for i := 0; i < rows; i++ {
		j := rand.Intn(i + 1)
		rowMap[i] = j
		rowMap[j] = i
	}
	return NewInstancesViewFromRows(from, rowMap)
}
359461
func (e *merryErr) WithStackSkipping(skip int) Error {
	if e == nil {
		return nil
	}
	return &merryErr{
		err:   e,
		key:   stack,
		value: captureStack(skip + 1),
	}
}
887334
func (q *Queue) lazyGrow() {
	if q.full() {
		q.resize(len(q.rep) * 2)
	}
}
390185
func (el *CallbackEventListener) RegAttachingToTangle(f SignalEventCallback) {
	el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
		f()
	}, event.EventAttachingToTangle))
}
364165
func (m *collection) idleMergerWaker() {
	idleTimeout := m.options.MergerIdleRunTimeoutMS
	if idleTimeout == 0 {
		idleTimeout = DefaultCollectionOptions.MergerIdleRunTimeoutMS
	}
	if idleTimeout <= 0 { // -1 will disable idle compactions.
		return
	}
	var prevRunID uint64 // Helps run idle merger IFF new data has come in.
	for {
		if atomic.LoadUint64(&m.stats.TotCloseBeg) > 0 {
			return
		}
		atomic.AddUint64(&m.stats.TotMergerIdleSleeps, 1)
		napIDBefore := atomic.LoadUint64(&m.stats.TotMergerWaitIncomingEnd)

		time.Sleep(time.Duration(idleTimeout) * time.Millisecond)

		napIDAfter := atomic.LoadUint64(&m.stats.TotMergerWaitIncomingEnd)
		napID := atomic.LoadUint64(&m.stats.TotMergerWaitIncomingBeg)
		if napID == napIDAfter+1 && // Merger is indeed asleep.
			napIDBefore == napIDAfter && // Nap only while merger naps.
			atomic.LoadUint64(&m.stats.TotMergerInternalEnd) > prevRunID { // New data.
			m.NotifyMerger("from-idle-merger", false)
			prevRunID = atomic.LoadUint64(&m.stats.TotMergerInternalEnd)
		}
	}
}
75142
func (cache *DiskBlockCacheLocal) shuffleTLFsAtPriorityWeighted(
	priority evictionPriority) []weightedByCount {
	weightedSlice := make([]weightedByCount, 0,
		len(cache.priorityTlfMap[priority]))
	idx := 0
	// Use an exponential distribution to ensure the weights are
	// correctly used.
	// See http://utopia.duth.gr/~pefraimi/research/data/2007EncOfAlg.pdf
	for tlfID, count := range cache.priorityTlfMap[priority] {
		if count == 0 {
			continue
		}
		weightedSlice = append(weightedSlice, weightedByCount{
			key:   math.Pow(rand.Float64(), 1.0/float64(count)),
			value: tlfID,
		})
		idx++
	}
	sort.Slice(weightedSlice, func(i, j int) bool {
		return weightedSlice[i].key > weightedSlice[j].key
	})
	return weightedSlice
}
284899
func (b *Builder) copySortedTables(oldTableID, newTableID int64) {
	if tableIDIsValid(oldTableID) {
		b.copySortedTablesBucket(tableBucketIdx(oldTableID))
	}
	if tableIDIsValid(newTableID) && newTableID != oldTableID {
		b.copySortedTablesBucket(tableBucketIdx(newTableID))
	}
}
108596
func (addrs byPriorityWeight) shuffleByWeight() {
	sum := 0
	for _, addr := range addrs {
		sum += int(addr.Weight)
	}
	for sum > 0 && len(addrs) > 1 {
		s := 0
		n := rand.Intn(sum)
		for i := range addrs {
			s += int(addrs[i].Weight)
			if s > n {
				if i > 0 {
					t := addrs[i]
					copy(addrs[1:i+1], addrs[0:i])
					addrs[0] = t
				}
				break
			}
		}
		sum -= int(addrs[0].Weight)
		addrs = addrs[1:]
	}
}
810718
func (q *TransmitLimitedQueue) lazyInit() {
	if q.tq == nil {
		q.tq = btree.New(32)
	}
	if q.tm == nil {
		q.tm = make(map[string]*limitedBroadcast)
	}
}
139647
func (s *Shuffler) Shuffle(data Interface) {
	rand.Shuffle(data.Len(), data.Swap)
}
237325
func Random(services []*registry.Service) Next {
	var nodes []*registry.Node

	for _, service := range services {
		nodes = append(nodes, service.Nodes...)
	}

	return func() (*registry.Node, error) {
		if len(nodes) == 0 {
			return nil, ErrNoneAvailable
		}

		i := rand.Int() % len(nodes)
		return nodes[i], nil
	}
}
619413
func shuffleStrings(list []string) {
	for i := range list {
		j := rand.Intn(i + 1)
		list[i], list[j] = list[j], list[i]
	}
}
729648
func Shuffle(data Interface) {
	n := data.Len()
	for i := n - 1; i >= 0; i-- {
		j := rand.Intn(i + 1)
		data.Swap(i, j)
	}
}
240360
func shuffleUp(heap Interface, i int) {
	for {
		pi := (i - 1) / 2 // (i + 1) / 2 - 1, parent
		if i == pi || !heap.Less(pi, i) {
			break
		}
		heap.Swap(pi, i)
		i = pi
	}
}
1010926
func LazyConvert(s string, a *Args) []string {
	if a == nil {
		args := NewArgs()
		a = &args
	}
	return LazyPinyin(s, *a)
}
928690
func (sd *StandardDeck) Shuffle(r *rand.Rand) {
	s := sd.Size()
	for k := range sd.cards {
		i := r.Intn(s)
		sd.cards[k], sd.cards[i] = sd.cards[i], sd.cards[k]
	}
}
9300
func (s SkipList) randomLevel() (n int) {
	for n = 0; n < s.effectiveMaxLevel() && rand.Float64() < p; n++ {
	}
	return
}