From 88ba591fc3b1b1057ded3e601f985860bf45e24a Mon Sep 17 00:00:00 2001 From: Christopher Crone Date: Fri, 22 May 2020 10:45:01 +0200 Subject: [PATCH] Seed random with nanosecond time It's possible that users will run commands more than once a second. Thus, seeding the random number generator with the current time in seconds could produce results like the same container name in subsequent commands. Seeding with the current time in nanoseconds reduces the probability of this. Signed-off-by: Christopher Crone --- azure/login/login.go | 5 ----- cli/main.go | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/azure/login/login.go b/azure/login/login.go index 3c13c543..dd4c63be 100644 --- a/azure/login/login.go +++ b/azure/login/login.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "log" - "math/rand" "net/url" "os/exec" "path/filepath" @@ -24,10 +23,6 @@ import ( "github.com/pkg/errors" ) -func init() { - rand.Seed(time.Now().Unix()) -} - //go login process, derived from code sample provided by MS at https://github.com/devigned/go-az-cli-stuff const ( authorizeFormat = "https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize?response_type=code&client_id=%s&redirect_uri=%s&state=%s&prompt=select_account&response_mode=query&scope=%s" diff --git a/cli/main.go b/cli/main.go index 110b8029..328a3a5c 100644 --- a/cli/main.go +++ b/cli/main.go @@ -30,11 +30,13 @@ package main import ( "context" "fmt" + "math/rand" "os" "os/exec" "os/signal" "path/filepath" "syscall" + "time" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -69,6 +71,8 @@ func init() { if err := os.Setenv("PATH", fmt.Sprintf("%s:%s", os.Getenv("PATH"), path)); err != nil { panic(err) } + // Seed random + rand.Seed(time.Now().UnixNano()) } func isOwnCommand(cmd *cobra.Command) bool {