diff --git a/id/random.go b/id/random.go index 0c804df..222833d 100644 --- a/id/random.go +++ b/id/random.go @@ -1,8 +1,8 @@ package id import ( - "fmt" "crypto/rand" + "fmt" ) // GenerateRandomString creates a random string of characters of the given @@ -24,3 +24,15 @@ func GenerateRandomString(dictionary string, l int) string { func GenSafeUniqueSlug(slug string) string { return fmt.Sprintf("%s-%s", slug, GenerateRandomString("0123456789bcdfghjklmnpqrstvwxyz", 4)) } + +// Generate62RandomString creates a random string with the given length +// consisting of characters in [A-Za-z0-9]. +func Generate62RandomString(l int) string { + return GenerateRandomString("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", l) +} + +// GenerateFriendlyRandomString creates a random string of characters with the +// given length consisting of characters in [a-z0-9]. +func GenerateFriendlyRandomString(l int) string { + return GenerateRandomString("0123456789abcdefghijklmnopqrstuvwxyz", l) +}