From 117d461c4944f189576f0c4967851de458ba6f32 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Mon, 4 Sep 2023 16:19:32 +0530 Subject: Updating README + Creating idgen package and importing it --- idgen/id_generator.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 idgen/id_generator.go (limited to 'idgen/id_generator.go') diff --git a/idgen/id_generator.go b/idgen/id_generator.go new file mode 100644 index 0000000..8c34f41 --- /dev/null +++ b/idgen/id_generator.go @@ -0,0 +1,29 @@ +// id_generator.go +package idgen + +import ( + "math/rand" + "time" +) + +const ( + // Define the character set for the generated IDs. + chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + + // Define the desired length of the generated IDs. + idLength = 8 +) + +// Initialize the random number generator. +func init() { + rand.Seed(time.Now().UnixNano()) +} + +// GenerateID generates a short and readable ID. +func GenerateID() string { + id := make([]byte, idLength) + for i := 0; i < idLength; i++ { + id[i] = chars[rand.Intn(len(chars))] + } + return string(id) +} -- cgit v1.2.3