// Int31n returns, as an int32, a non-negative pseudo-random number in [0,n)
// from the source in the context or the shared global source.
//
// It panics if n <= 0.
506665
func (l *Locking) Int31n(n int32) (v int32) {
	l.Lock()
	v = l.R.Int31n(n)
	l.Unlock()
	return
}
1035190
func Uint64n(n uint64) uint64 {
	if n == 0 {
		panic("fastrand: argument to Uint64n is 0")
	}
	// To eliminate modulo bias, keep selecting at random until we fall within
	// a range that is evenly divisible by n.
	// NOTE: since n is at most math.MaxUint64, max is minimized when:
	//    n = math.MaxUint64/2 + 1 -> max = math.MaxUint64 - math.MaxUint64/2
	// This gives an expected 2 tries before choosing a value < max.
	max := math.MaxUint64 - math.MaxUint64%n
	b := Bytes(8)
	r := *(*uint64)(unsafe.Pointer(&b[0]))
	for r >= max {
		Read(b)
		r = *(*uint64)(unsafe.Pointer(&b[0]))
	}
	return r % n
}
98729
func (m *MT19937) Int31() int32 {
	var y uint32

	m.left--
	if m.left == 0 {
		m.NextState()
	}

	m.nptr++
	y = uint32(m.next[m.nptr])

	// Tempering
	y ^= (y >> 11)
	y ^= (y << 7) & 0x9d2c5680
	y ^= (y << 15) & 0xefc60000
	y ^= (y >> 18)

	return int32(y & LMask)
}
1272328
func MinUint8N(v ...uint8) uint8 {
	switch len(v) {
	case 0:
		return 0
	case 1:
		return v[0]
	case 2:
		return MinUint8(v[0], v[1])
	default:
		l := len(v) / 2
		return MinUint8N(MinUint8N(v[:l]...), MinUint8N(v[l:]...))
	}
}
975014
func NumberToInt(number interface{}) (int64, error) {
	switch v := number.(type) {
	case int32:
		return int64(v), nil
	case int64:
		return v, nil
	case float32:
		return int64(v), nil
	case float64:
		return int64(v), nil
	}
	result, err := strconv.ParseInt(fmt.Sprintf("%v", number), 10, 64)
	if err != nil {
		return 0, err
	}
	return result, nil
}
349163
func NewN(ie interface{}, n int, a ...interface{}) error {
	if ie == nil {
		return nil
	}
	switch err := ie.(type) {
	case *Error:
		return err
	case string:
		return newError(err, 2+n, a...)
	case error:
		return newError(err, 2+n, a...)
	default:
		panic("invalid error type")
	}
}
1221750
func (g *Group) Int32() *Statement {
	// notest
	s := Int32()
	g.items = append(g.items, s)
	return s
}
659921
func (tr Row) Uint64(nn int) (val uint64) {
	val, err := tr.Uint64Err(nn)
	if err != nil {
		panic(err)
	}
	return
}
454631
func (lr *LockedRand) Int63n(n int64) (r int64) {
	lr.lk.Lock()
	r = lr.r.Int63n(n)
	lr.lk.Unlock()
	return
}
730715
func (s *stack) NipN(idx int32) error {
	_, err := s.nipN(idx)
	return err
}
670933
func Int63n(n int64) int64 {
	mu.Lock()
	res := r.Int63n(n)
	mu.Unlock()
	return res
}
1080461
func RandomInt(n int) int {
	if n <= 0 {
		panic(fmt.Sprintf("Got invalid (non positive) value: %d", n))
	}
	m := int(RandomUInt64()) % n
	if m < 0 {
		return n + m
	}
	return m
}
790902
func IndexN(s, sep string, n int) int {
	sepIdx := 0
	for i := 0; i < n; i++ {
		nextIdx := strings.Index(s[sepIdx:], sep)
		if nextIdx == -1 {
			return -1 // ### return, not found ###
		}
		sepIdx += nextIdx + 1
	}
	return sepIdx - 1
}
479177
func (lr *LockedRand) Intn(n int) (r int) {
	lr.lk.Lock()
	r = lr.r.Intn(n)
	lr.lk.Unlock()
	return
}
952951
func (ung UniformGenerator) Int32() int32 {
	ung.mu.Lock()
	defer ung.mu.Unlock()
	return ung.rd.Int31()
}
1274875
func MinUint64N(v ...uint64) uint64 {
	switch len(v) {
	case 0:
		return 0
	case 1:
		return v[0]
	case 2:
		return MinUint64(v[0], v[1])
	default:
		l := len(v) / 2
		return MinUint64N(MinUint64N(v[:l]...), MinUint64N(v[l:]...))
	}
}
73497
func ReverseUint64N(v uint64, n uint) (x uint64) {
	return ReverseUint64(v << (64 - n))
}