diff options
author | Andinus <andinus@inventati.org> | 2020-03-16 02:24:57 +0530 |
---|---|---|
committer | Andinus <andinus@inventati.org> | 2020-03-16 02:24:57 +0530 |
commit | b5887c34637d87d41e07058f64470469304ba9aa (patch) | |
tree | 85b3c2997e0af171620af6a432a7b5248da26b17 | |
parent | c6cd3372c23bac2d2662ebf55daa9dd35ddd5363 (diff) | |
download | cetus-b5887c34637d87d41e07058f64470469304ba9aa.tar.gz |
Add RandAlNum function
-rw-r--r-- | pkg/cetus/random.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/cetus/random.go b/pkg/cetus/random.go new file mode 100644 index 0000000..d77a24b --- /dev/null +++ b/pkg/cetus/random.go @@ -0,0 +1,16 @@ +package cetus + +import ( + "math/rand" +) + +// RandAlNum returns random alpha-numeric string of specific length +func RandAlNum(n int) string { + rand.Seed(time.Now().UnixNano()) + const alphanum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + b := make([]byte, n) + for i := range b { + b[i] = letterBytes[rand.Intn(len(letterBytes))] + } + return string(b) +} |