You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
430 B
Go

package internal
import (
"crypto/rand"
"encoding/base64"
)
func GenerateRandomString(length int) (string, error) {
// Determine the number of random bytes needed
bytes := make([]byte, length)
_, err := rand.Read(bytes)
if err != nil {
return "", err
}
// Encode the random bytes to base64
randomString := base64.URLEncoding.EncodeToString(bytes)
// Trim to the desired length
return randomString[:length], nil
}