Skip to content

Instantly share code, notes, and snippets.

@SuperC03
Created May 17, 2020 00:51
Show Gist options
  • Save SuperC03/a96ec63e0c465bd9cd0587aa87bce898 to your computer and use it in GitHub Desktop.
Save SuperC03/a96ec63e0c465bd9cd0587aa87bce898 to your computer and use it in GitHub Desktop.
Used to Generate Random URL's for Link Shorteners
func randString(length int) string {
// Chars to Choose From
chars := []byte("abcdefghijklmnopqqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
// Output String
output := ""
// Seed the Random Object for Random-ness
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
// Generate String to Specified Length
for i := 0; i < length; i++ {
// Add Random Character from Specified List
output += string(chars[r1.Intn(len(chars))])
}
return output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment