Skip to content

Instantly share code, notes, and snippets.

@mcos
Created March 27, 2015 14:37
Show Gist options
  • Save mcos/ad382848e4ae905f7224 to your computer and use it in GitHub Desktop.
Save mcos/ad382848e4ae905f7224 to your computer and use it in GitHub Desktop.
Generate a 128 character random string in Go
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