Skip to content

Commit

Permalink
use crypto/rand instead of math/rand
Browse files Browse the repository at this point in the history
  • Loading branch information
pb82 committed Apr 8, 2020
1 parent 6e0a06d commit 75c77df
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pkg/controller/model/utils.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package model

import (
"math/rand"
"crypto/rand"
"encoding/base64"
)

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func RandStringRunes(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
func generateRandomBytes(n int) []byte {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
panic(err)
}
return string(b)
return b
}

func RandStringRunes(s int) string {
b := generateRandomBytes(s)
return base64.URLEncoding.EncodeToString(b)
}

func MergeAnnotations(requested map[string]string, existing map[string]string) map[string]string {
Expand Down

0 comments on commit 75c77df

Please sign in to comment.