//RandomStr 随机生成字符串
763221
func RandomStr(length int) string {
	str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	bytes := []byte(str)
	result := []byte{}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := 0; i < length; i++ {
		result = append(result, bytes[r.Intn(len(bytes))])
	}
	return string(result)
}
961786
func RandToken(size int) string {
	buf := make([]byte, size)
	if n, err := rand.Read(buf); err != nil || n != len(buf) {
		panic("failed to get random: " + err.Error())
	}
	return fmt.Sprintf("%x", buf)
}
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))
}
740861
func randbytes(n int) []byte {
	buf := make([]byte, n)
	if _, err := rand.Read(buf); err != nil {
		panic(fmt.Sprintf("failed to generate %d random bytes: %v", n, err))
	}
	return buf
}
1076955
func ShuffleStrings(s []string) []string {
	if s == nil {
		return nil
	}
	shuffled := make([]string, len(s))
	perm := utilrand.Perm(len(s))
	for i, j := range perm {
		shuffled[j] = s[i]
	}
	return shuffled
}
947678
func RandomAlpha(prefix string, length int) string {
	return RandomRunes(prefix, length, AlphaRunes)
}
258944
func randString(n int, src rand.Source, prefix string) string {
	b := make([]byte, n)
	// A rand.Int63() generates 63 random bits, enough for letterIdxMax letters!
	for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; {
		if remain == 0 {
			cache, remain = src.Int63(), letterIdxMax
		}
		if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
			b[i] = letterBytes[idx]
			i--
		}
		cache >>= letterIdxBits
		remain--
	}
	return prefix + string(b[0:30-len(prefix)])
}
1280539
function randstr(options) {
    var opt = _validateOptions(options);
    var from, to;
    if (Array.isArray(opt.length)) {
        _a = opt.length, from = _a[0], to = _a[1];
    }
    else {
        from = to = opt.length;
    }
    var str = '';
    if (0 === to) {
        return str;
    }
    var charsIsString = 'string' === typeof opt.chars;
    var charsLastIndex = charsIsString ? opt.chars.length - 1 : 0;
    var includeControlChars = true === opt.includeControlChars;
    var hasAcceptableFunc = 'function' === typeof opt.acceptable;
    var hasReplacer = 'function' === typeof opt.replacer;
    var max = _randomIntBetween(opt.random, from, to);
    // console.log( 'max', max, 'from', from, 'to', to );
    for (var i = 0, len = 0, charCode = void 0, chr = void 0; i < max && len < max; ++i) {
        if (charsIsString) {
            var index = _randomIntBetween(opt.random, 0, charsLastIndex);
            charCode = opt.chars.charCodeAt(index);
        }
        else {
            charCode = _randomIntBetween(opt.random, opt.chars[0], opt.chars[1]);
        }
        // Non printable?
        if (!includeControlChars && _isControlChar(charCode)) {
            // console.log( 'NOT PRINTABLE!');
            --i; // back to try again
            continue;
        }
        chr = String.fromCharCode(charCode);
        // console.log( 'charCode', charCode, 'char', chr );
        if (hasAcceptableFunc && !opt.acceptable.call(null, chr)) {
            --i; // back to try again
            continue;
        }
        if (hasReplacer) {
            chr = opt.replacer.call(null, chr);
            // console.log( 'char after', chr );
            // Their combined length pass the limit?
            if ((len + chr.length) > max) {
                // console.log( 'greater than max!', 'i', i, 'max', max, 'str', len, 'chr', chr.length );
                --i; // back to try again
                continue;
            }
        }
        str += chr;
        len = str.length;
    }
    return str;
    var _a;
}
1015707
func randomPassword() (string, error) {
	limit := 100
	for ; limit >= 0; limit-- {
		s, err := generatePassword()
		if err != nil {
			return "", err
		}
		if validPassword(s) {
			return s, nil
		}
	}
	return "", errors.New("failed to generate valid Windows password")
}
1358458
func RandomBytes(n int) []byte {
	key := make([]byte, n)
	_, err := io.ReadFull(rand.Reader, key)
	if err != nil {
		log.Panicf("auth: could not generate random bytes: %s", err)
	}
	return key
}
700084
func GenerateRandomName(prefix string, size int) (string, error) {
	id := make([]byte, 32)
	if _, err := io.ReadFull(rand.Reader, id); err != nil {
		return "", err
	}
	return prefix + hex.EncodeToString(id)[:size], nil
}
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
	}
}
213666
func StringR(l int) (string, error) {
	s, err := String(l, "/dev/random")
	return s, e.Forward(err)
}
114746
func RandomLengthDelim(length int, delim, lang string) (string, error) {
	g := xkcdpwgen.NewGenerator()
	g.SetNumWords(length)
	g.SetDelimiter(delim)
	g.SetCapitalize(delim == "")
	if err := g.UseLangWordlist(lang); err != nil {
		return "", err
	}
	return string(g.GeneratePassword()), nil
}
1076759
func randString(r *rand.Rand) string {
	n := r.Intn(20)
	runes := make([]rune, n)
	for i := range runes {
		runes[i] = unicodeRanges[r.Intn(len(unicodeRanges))].choose(r)
	}
	return string(runes)
}
1280517
func RandomKey() string {
	k := make([]byte, 12)
	for bytes := 0; bytes < len(k); {
		n, err := rand.Read(k[bytes:])
		if err != nil {
			panic("rand.Read() failed")
		}
		bytes += n
	}
	return base64.StdEncoding.EncodeToString(k)
}
646319
func RandString(n int, defaultCharsets ...string) string {
	charset := DefaultCharset
	if len(defaultCharsets) > 0 {
		charset = defaultCharsets[0]
	}

	result, err := randutil.String(n, charset)
	if err != nil {
		fmt.Println("goutils RandString error:", err)
		return Md5(strconv.Itoa(rand.Intn(999999)))
	}

	return result
}