From 9f14466dfa8660362a4e51b3c8c6810bf8d66a22 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 5 Mar 2023 22:24:25 +0100 Subject: [PATCH] fix: lint --- pkg/modules/auth/openid/openid.go | 4 +--- pkg/utils/random_string.go | 9 +++------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/pkg/modules/auth/openid/openid.go b/pkg/modules/auth/openid/openid.go index 9509e52ea..b33a858f4 100644 --- a/pkg/modules/auth/openid/openid.go +++ b/pkg/modules/auth/openid/openid.go @@ -20,9 +20,7 @@ import ( "context" "encoding/json" "errors" - "math/rand" "net/http" - "time" "code.vikunja.io/web/handler" @@ -66,7 +64,7 @@ type claims struct { } func init() { - rand.Seed(time.Now().UTC().UnixNano()) + petname.NonDeterministicMode() } func (p *Provider) setOicdProvider() (err error) { diff --git a/pkg/utils/random_string.go b/pkg/utils/random_string.go index 4c5f90f33..fa9bdd0f4 100644 --- a/pkg/utils/random_string.go +++ b/pkg/utils/random_string.go @@ -21,10 +21,6 @@ import ( "time" ) -func init() { - rand.Seed(time.Now().UnixNano()) -} - const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" const ( letterIdxBits = 6 // 6 bits to represent a letter index @@ -34,11 +30,12 @@ const ( // MakeRandomString return a random string func MakeRandomString(n int) string { + source := rand.New(rand.NewSource(time.Now().UnixNano())) b := make([]byte, n) // A rand.Int63() generates 63 random bits, enough for letterIdxMax letters! - for i, cache, remain := n-1, rand.Int63(), letterIdxMax; i >= 0; { + for i, cache, remain := n-1, source.Int63(), letterIdxMax; i >= 0; { if remain == 0 { - cache, remain = rand.Int63(), letterIdxMax + cache, remain = source.Int63(), letterIdxMax } if idx := int(cache & letterIdxMask); idx < len(letterBytes) { b[i] = letterBytes[idx]