Created
October 31, 2015 16:46
-
-
Save yinyin/37687588ed68c12b61de to your computer and use it in GitHub Desktop.
Function to generate random password
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
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