package util
import (
"crypto/rand"
"encoding/hex"
)
// GenerateRandomString generates a random string of the specified length using hex encoding.
func GenerateRandomString(length int) string {
bytes := make([]byte, (length+1)/2) // Need half the bytes for hex encoding
if _, err := rand.Read(bytes); err != nil {
// Fallback to a simple timestamp-based approach if crypto/rand fails
return hex.EncodeToString([]byte("fallback"))[:length]
}
result := hex.EncodeToString(bytes)
if len(result) > length {
return result[:length]
}
return result
}