Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10592326
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/id/random.go b/id/random.go
index 0c804df..222833d 100644
--- a/id/random.go
+++ b/id/random.go
@@ -1,26 +1,38 @@
package id
import (
- "fmt"
"crypto/rand"
+ "fmt"
)
// GenerateRandomString creates a random string of characters of the given
// length from the given dictionary of possible characters.
//
// This example generates a hexadecimal string 6 characters long:
// GenerateRandomString("0123456789abcdef", 6)
func GenerateRandomString(dictionary string, l int) string {
var bytes = make([]byte, l)
rand.Read(bytes)
for k, v := range bytes {
bytes[k] = dictionary[v%byte(len(dictionary))]
}
return string(bytes)
}
// GenSafeUniqueSlug generatees a reasonably unique random slug from the given
// original slug. It's "safe" because it uses 0-9 b-z excluding vowels.
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)
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Apr 27, 8:41 AM (15 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217019
Attached To
rWC Write.as Web Core
Event Timeline
Log In to Comment