package util import ( "math/rand" "time" ) var defaultLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") // RandomString returns a random string with a fixed length func RandomString(n int, allowedChars ...[]rune) string { var letters []rune if len(allowedChars) == 0 { letters = defaultLetters } else { letters = allowedChars[0] } b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) } func RandInt64(min, max int64) int64 { s := rand.NewSource(time.Now().UnixNano()) r := rand.New(s) return min + r.Int63n(max-min+1) } func RandFloat64(min, max float64) float64 { s := rand.NewSource(time.Now().UnixNano()) r := rand.New(s) return min + r.Float64()*(max-min) }