Skip to content

Instantly share code, notes, and snippets.

@yinyin
Created October 31, 2015 16:46
Show Gist options
  • Save yinyin/37687588ed68c12b61de to your computer and use it in GitHub Desktop.
Save yinyin/37687588ed68c12b61de to your computer and use it in GitHub Desktop.
Function to generate random password
import "time"
import "math/rand"
func init() {
rand.Seed(time.Now().Unix())
}
func GenerateRandomPassword(length int) string {
const base_string = "2346789BCDFGHJKMPQRTVWXY"
const l_base_string = len(base_string)
var buf []byte = make([]byte, length)
for i := range buf {
buf[i] = base_string[rand.Intn(l_base_string)]
}
return string(buf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment