Created
May 17, 2020 00:51
-
-
Save SuperC03/a96ec63e0c465bd9cd0587aa87bce898 to your computer and use it in GitHub Desktop.
Used to Generate Random URL's for Link Shorteners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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