Skip to content

Commit 1028e97

Browse files
author
wintrmvte
committed
+ RandomStringCharset()
1 parent 5a2188a commit 1028e97

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Diff for: random.go

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ func RandomString(n int) string {
3434
return string(b)
3535
}
3636

37+
//RandomStringCharset returns a string of a given length from provided charset
38+
func RandomStringCharset(strlen int, chars string) string {
39+
b := make([]byte, strlen)
40+
for i := range b {
41+
b[i] = chars[rand.Intn(len(chars))]
42+
}
43+
return string(b)
44+
}
45+
3746
// Returns a random true/false
3847
func RandomBool() bool {
3948
rand.Seed(time.Now().UnixNano())

0 commit comments

Comments
 (0)