govote/utils/random.go

18 lines
458 B
Go
Raw Permalink Normal View History

2024-05-12 22:47:24 +00:00
package utils
import (
"math/rand"
)
const charSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
2024-05-14 08:26:48 +00:00
// GenerateRandomString takes a length and returns a random string of that length.
// This function is used for generating random IDs for the votings.
2024-05-12 22:47:24 +00:00
func GenerateRandomString(length int) string {
2024-05-13 08:45:38 +00:00
result := make([]byte, length)
for i := 0; i < length; i++ {
result[i] = charSet[rand.Intn(len(charSet))]
}
return string(result)
2024-05-12 22:47:24 +00:00
}