Skip to content

Instantly share code, notes, and snippets.

@p4tin
Last active January 18, 2018 04:04
Show Gist options
  • Save p4tin/178792d020dfffb83e61c6be0b53ba01 to your computer and use it in GitHub Desktop.
Save p4tin/178792d020dfffb83e61c6be0b53ba01 to your computer and use it in GitHub Desktop.
package main
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func GetSlug(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}
func main() {
rand.Seed(time.Now().UTC().UnixNano())
slug := GetSlug(8)
println(slug)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment