// Returns a random offset between 0 and n
356408
func randomOffset(n int) int {
	if n == 0 {
		return 0
	}
	return int(rand.Uint32() % uint32(n))
}
672324
func getRandom(i int) []byte {
	b := make([]byte, i)
	for {
		// keep trying till we get it
		if _, err := rand.Read(b); err != nil {
			continue
		}
		return b
	}
}
1273672
func (r *Rand) Float32() float32 {
	// Same rationale as in Float64: we want to preserve the Go 1 value
	// stream except we want to fix it not to return 1.0
	// There is a double rounding going on here, but the argument for
	// mapping 1 to 0 still applies: 0 was underrepresented before,
	// so mapping 1 to 0 doesn't cause too many 0s.
	// This only happens 1/2²⁴ of the time (plus the 1/2⁵³ of the time in Float64).
	f := float32(Float64())
	if f == 1 {
		f = 0
	}
	return f
}
879496
func IntnRange(min, max int) int {
	rng.Lock()
	defer rng.Unlock()
	return rng.rand.Intn(max-min) + min
}
392103
func RandomBits(bits int) []byte {
	size := bits / 8
	if bits%8 != 0 {
		size++
	}
	b := make([]byte, size)
	if _, err := rand.Read(b); err != nil {
		panic(err) // rand should never fail
	}
	return b
}
658153
func GetRandomBytes(len int) ([]byte, error) {
	if len < 0 {
		return nil, errors.New("Len must be larger than 0")
	}

	buffer := make([]byte, len)

	n, err := rand.Read(buffer)
	if err != nil {
		return nil, err
	}
	if n != len {
		return nil, fmt.Errorf("Buffer not filled. Requested [%d], got [%d]", len, n)
	}

	return buffer, nil
}
739349
func RandomizeOutputPosition(outputs []*wire.TxOut, index int) int {
	r := cprng.Int31n(int32(len(outputs)))
	outputs[r], outputs[index] = outputs[index], outputs[r]
	return int(r)
}
1137390
func (c *Client) Random(random bool) error {
	if random {
		return c.Command("random 1").OK()
	}
	return c.Command("random 0").OK()
}
1042693
func RandomValuesWithMax(count int, max float64) []float64 {
	return Seq{NewRandom().WithMax(max).WithLen(count)}.Array()
}
301027
func RandomString(length int) string {
	var dat = make([]byte, length)
	rand.Read(dat)
	return base64.StdEncoding.EncodeToString(dat)
}
922976
func RandFloat64() float64 {
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	return r.Float64()
}
148480
func GetRandomChars(c string, n int) (string, error) {
	var r string

	// Get random chars one by one
	for i := 0; i < n; i++ {
		// Read random position
		p, err := rand.Int(rand.Reader, big.NewInt(int64(len(c))))
		if err != nil {
			return "", err
		}

		r += string(c[p.Int64()])
	}

	return r, nil
}
894145
func rnd(from, to int) int {
	return rand.Intn(to+1-from) + from
}
250787
func Rand(max int) int {
	i, _ := rand.Int(rand.Reader, big.NewInt(int64(max)))
	return int(i.Int64())
}
377766
func RandRangeInt64(min, max int64) int64 {
	if min >= max || min == 0 || max == 0 {
		return max
	}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	return r.Int63n(max-min) + min
}
1341649
func GenerateRandomBytes(n int) ([]byte, error) {
	b := make([]byte, n)
	_, err := rand.Read(b)

	if err != nil {
		zap.L().Debug("GenerateRandomBytes failed", zap.Error(err))
		return nil, err
	}

	s := base64.StdEncoding.EncodeToString(b)

	return []byte(s[:n]), nil
}
14824
func randomNonZero() uint64 {
	buf := make([]byte, 8)
	n, err := io.ReadFull(rand.Reader, buf)
	if err != nil || n != 8 {
		panic("Unable to fully read from rand.Reader")
	}
	u, x := binary.Uvarint(buf)
	if u == 0 || x == 0 || x < 0 {
		return randomNonZero()
	}
	return u
}