Created
March 27, 2015 14:37
-
-
Save mcos/ad382848e4ae905f7224 to your computer and use it in GitHub Desktop.
Generate a 128 character random string in Go
This file contains hidden or 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
package main | |
import ( | |
"crypto/rand" | |
"fmt" | |
) | |
func randStr(strSize int) string { | |
dictionary := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
var bytes = make([]byte, strSize) | |
rand.Read(bytes) | |
for k, v := range bytes { | |
bytes[k] = dictionary[v%byte(len(dictionary))] | |
} | |
return string(bytes) | |
} | |
func main() { | |
fmt.Println(randStr(128)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment