You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
629 B

package randomstring
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func Gen(length int, lower bool, upper bool, num bool) string {
r := [3]string{"abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "1234567890",}
chars := []rune("")
if lower {
chars = []rune(string(chars) + r[0])
}
if upper {
chars = []rune(string(chars) + r[1])
}
if num {
chars = []rune(string(chars) + r[2])
}
str := make([]rune, length)
for i := range str {
str[i] = chars[rand.Intn(len(chars))]
}
return string(str)
}