1
0
Fork 0
mirror of synced 2024-05-29 13:31:12 -04:00
openvpn-user/src/utils.go
2022-11-29 18:22:39 +03:00

25 lines
510 B
Go

package src
import "crypto/rand"
func RandStr(strSize int, randType string) string {
var dictionary string
switch randType {
case "number":
dictionary = "0123456789"
case "alpha":
dictionary = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
default:
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)
}