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 <christopher.crone@docker.com>
This commit is contained in:
Christopher Crone 2020-05-22 10:45:01 +02:00
parent dd66646c06
commit 88ba591fc3
2 changed files with 4 additions and 5 deletions

View File

@ -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"

View File

@ -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 {