From c856c7e66e3ad29ea0491f1f4951b31deb8279ea Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 20 Oct 2019 16:53:28 +0200 Subject: functional --- src/access.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/access.go (limited to 'src/access.go') diff --git a/src/access.go b/src/access.go new file mode 100644 index 0000000..6de2c05 --- /dev/null +++ b/src/access.go @@ -0,0 +1,26 @@ +package main + +import ( + "math/rand" + "strings" + "time" +) + +func newAccessCode(length int) string { + // seed the random numbergenerator + rand.Seed(time.Now().UnixNano()) + + // define the alphabet + chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + + "abcdefghijklmnopqrstuvwxyz" + + "0123456789") + + // build the accesscode + var b strings.Builder + for i := 0; i < length; i++ { + b.WriteRune(chars[rand.Intn(len(chars))]) + } + str := b.String() + + return str +} -- cgit 1.4.1