package utils

import "crypto/rand"

const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

func RandStr(length int) string {

	bytes := make([]byte, length)
	if _, err := rand.Read(bytes); err != nil {
		panic(err)
	}

	// 将随机字节数组转换为随机字符串
	result := make([]byte, length)
	for i := 0; i < length; i++ {
		result[i] = charset[int(bytes[i])%len(charset)]
	}

	return string(result)
}
