From b5887c34637d87d41e07058f64470469304ba9aa Mon Sep 17 00:00:00 2001 From: Andinus Date: Mon, 16 Mar 2020 02:24:57 +0530 Subject: Add RandAlNum function --- pkg/cetus/random.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 pkg/cetus/random.go (limited to 'pkg') 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) +} -- cgit 1.4.1-2-gfad0