// Fake random number generator, never use in production. Always returns
// a predictable hex-encoded (base16) string that looks like "00010203..."
494972
func (f *FakeRNG) HexDigest(bytes int) (string, error) {
	return hexDigest(f, bytes)
}
335023
func (b *builtinRandomBytesSig) evalString(row chunk.Row) (string, bool, error) {
	len, isNull, err := b.args[0].EvalInt(b.ctx, row)
	if isNull || err != nil {
		return "", true, err
	}
	if len < 1 || len > 1024 {
		return "", false, types.ErrOverflow.GenWithStackByArgs("length", "random_bytes")
	}
	buf := make([]byte, len)
	if n, err := rand.Read(buf); err != nil {
		return "", true, err
	} else if int64(n) != len {
		return "", false, errors.New("fail to generate random bytes")
	}
	return string(buf), false, nil
}
1019385
func GenerateHexspeakUUID(i int) (string, error) {
	if i < 0 {
		i = -i
	}
	hexspeaks := []string{
		"0ff1ce",
		"31337",
		"4b1d",
		"badc0de",
		"badcafe",
		"badf00d",
		"deadbabe",
		"deadbeef",
		"deadc0de",
		"deadfeed",
		"fee1bad",
	}
	return FormatUUID(hexspeaks[i%len(hexspeaks)])
}
1027779
func RandN32(n int) []uint32 {
	b := make([]byte, 4*n)
	if _, err := rand.Read(b); err != nil {
		panic("unable to get random numbers: " + err.Error())
	}
	r := make([]uint32, n)
	for i := range r {
		r[i] = binary.LittleEndian.Uint32(b[4*i : (4*i + 4)])
	}
	return r
}
297586
func GenUUID() string {
	uuid := make([]byte, 24)
	n, err := rand.Read(uuid)
	if n != len(uuid) || err != nil {
		log.Fatal("can't generate uuid")
		return ""
	}
	// TODO: verify the two lines implement RFC 4122 correctly
	uuid[8] = 0x80 // variant bits see page 5
	uuid[4] = 0x40 // version 4 Pseudo Random, see page 7

	str := hex.EncodeToString(uuid)
	return fmt.Sprintf("%s-%s-%s-%s-%s", str[:8], str[9:13], str[14:18], str[19:23], str[29:])
}
386716
func (enc *Encoding) Random(n int) (string, error) {
	buf := make([]byte, n)
	_, err := rand.Reader.Read(buf)
	if err != nil {
		return "", err
	}
	return enc.EncodeToString(buf), nil
}
1205852
func Generate() string {
	rand.Seed(time.Now().UTC().UnixNano())

	cnpj := make([]int, 12)
	for i := 0; i < 12; i++ {
		cnpj[i] = rand.Intn(9)
	}
	checkDigit1 := computeCheckDigit(cnpj)
	cnpj = append(cnpj, checkDigit1)
	checkDigit2 := computeCheckDigit(cnpj)
	cnpj = append(cnpj, checkDigit2)

	var str string
	for _, value := range cnpj {
		str += strconv.Itoa(value)
	}
	return str
}
15924
func (h *Haikunator) randomString(s []string) string {
	size := len(s)

	if size <= 0 {
		return ""
	}

	return s[h.Random.Intn(size)]
}
1053201
func GenerateRandomUUID(length int) (string, error) {
	var letters = []rune("abcdef0123456789")

	b := make([]rune, length)
	for i := range b {
		b[i] = letters[rand.Intn(len(letters))]
	}
	return FormatUUID(string(b))
}
1162755
func CryptoRandomHex(len int) (string, error) {
	randomBytes := make([]byte, len)
	if _, err := rand.Reader.Read(randomBytes); err != nil {
		return "", trace.Wrap(err)
	}
	return hex.EncodeToString(randomBytes), nil
}
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
}
1300134
func GenerateRandomString(strLen int) string {
	rand.Seed(time.Now().UTC().UnixNano())
	const chars = "ABCDEF0123456789"
	result := make([]byte, strLen)
	for i := 0; i < strLen; i++ {
		result[i] = chars[rand.Intn(len(chars))]
	}
	return string(result)
}
908817
func RandomString(count int, set ...[]byte) string {
	var sets []byte
	var ret = make([]byte, count)
	if len(set) == 0 {
		sets = []byte(ALPHANUM)
		setlen := len(ALPHANUM)
		for i := 0; i < count; i++ {
			ret[i] = sets[RandomInt(0, setlen-1)]
		}
		return string(ret)
	}

	return ""
}
925826
func (p *packetNumberGenerator) getRandomNumber() uint16 {
	b := make([]byte, 2)
	rand.Read(b) // ignore the error here

	num := uint16(b[0])<<8 + uint16(b[1])
	return num
}
1342155
func RandomString(byteLength int) string {
	b := make([]byte, byteLength)
	_, err := io.ReadFull(RandReader, b)
	if err != nil {
		panic(fmt.Sprintf("Error reading random bytes: %s", err))
	}
	return base64.RawURLEncoding.EncodeToString(b)
}
289501
func Generate() string {
	rand.Seed(time.Now().UTC().UnixNano())

	data := make([]int, 9)
	for i := 0; i < 9; i++ {
		data[i] = rand.Intn(9)
	}
	checkDigit1 := computeCheckDigit(data)
	data = append(data, checkDigit1)
	checkDigit2 := computeCheckDigit(data)
	data = append(data, checkDigit2)

	var cpf string
	for _, value := range data {
		cpf += strconv.Itoa(value)
	}
	return cpf
}
845391
func GenerateUUID() (string, error) {
	buf, err := GenerateRandomBytes(uuidLen)
	if err != nil {
		return "", err
	}
	return FormatUUID(buf)
}